Help... Template Question for my class

Posted on 2001-08-10
Last Modified: 2010-04-02
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


Question by:screwdriver

Expert Comment

ID: 6371639
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>;
LVL 30

Expert Comment

ID: 6371691
Please list the errors that you need help with, so we're sure we cover them all.

Expert Comment

ID: 6371754
extension of ur source file is .cpp?

Expert Comment

ID: 6371896
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.

Author Comment

ID: 6375101
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??
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


Author Comment

ID: 6375105
the NULL thing was my fault. I just need to put #include <iostream.h> and it  fixed the problem.

Accepted Solution

jasonclarke earned 100 total points
ID: 6379368
Answer in response to screwdrivers request...

Expert Comment

ID: 6806117

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

Expert Comment

ID: 6901312

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.

Expert Comment

ID: 7024314
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now