Help... Template Question for my class

When I want to compile the following code, I got a bunch of errors that I don't understand... please help.

#include "llist.h"
#include <iostream.h>

int main ()
  LinkedList<int> *test;
  test = new LinkedList<int> (1);
  return 0;

#ifndef _LLIST_H_
#define _LLIST_H_

template <class T>
class ListNode
  friend class LinkedList;

  T data;          // node data
  ListNode* next;  // pointer to the next node      

  // constructor
  ListNode (T item, ListNode* pListNode = NULL)
    : data(item), next(pListNode) {}

template <class T>
class LinkedList
  // constructor
  LinkedList () : head(NULL) {}
  LinkedList (T item) : head (new ListNode<T> (item, NULL)) {}

  // destructor
  ~LinkedList ();

  ListNode<T>* head;     // pointer to the first node of list


Who is Participating?
jasonclarkeConnect With a Mentor Commented:
Answer in response to screwdrivers request...
There are just two problems, both to do with declarations,
because of the ordering here, you need to declare the fact that LinkedList is a class (so that the Node class can see it), so add:

template <class T>
class LinkedList;

at the top of the file (before the node class),  and the friend declaration needs a template argument, so change the friend line to:

friend class LinkedList<T>;
Please list the errors that you need help with, so we're sure we cover them all.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

extension of ur source file is .cpp?
With the source code above, the only errors are those I mentioned - accoriding to VC++ anyway.  One minor thing is that 'NULL' is not defined by default and should either be defined or (better) replaced by 0.
screwdriverAuthor Commented:
jason, post your comment as an answer. I'll give the point to you.

daknight, no.. it's .C, i am using gnu c++ compiler.. and I thought .cpp is only in VC++, is it??
screwdriverAuthor Commented:
the NULL thing was my fault. I just need to put #include <iostream.h> and it  fixed the problem.

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.

EXPERTS: Please leave your thoughts on this question here.


Community Support Moderator
Experts Exchange

ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
Force accepted

** Mindphaser - Community Support Moderator **
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.