i have this part of my link list program

template <class E> LinkedList<E>::node * LinkedList<E>::getNode{
...
...
}(const E &item)

and my compiler, bloodshed dev c++, says
expected constructor, destructor, or type conversion before "*" token
expected ";" before "*" token

i don't think there is an syntax error but can someone explain this..

Recommended Answers

All 6 Replies

I may be missing something but why do you have (const E &item) _after_ the braces?

opps, sorry there is a mistake while posting it here..ill edit it..

it is actually

template <class E> LinkedList<E>::node * LinkedList<E>::getNode(const E &item)
{
//some lines here
}

Do you have the method definitions in the same header file with the declarations? It kinda runs counter to your experience with headers but for templates it's usually necessary.

Do you have the method definitions in the same header file with the declarations? It kinda runs counter to your experience with headers but for templates it's usually necessary.

yup..i declared it my class right after the declaration of the struct

something like this

//template class declaration
{
      struct node {

      }
      node *getNode (/*parameters*/);//here is the declaration on the very the same header file
};

actually this is a class on linked lists..

i'm sorry but i don't understand what you mean by "It kinda runs counter to your experience with headers but for templates it's usually necessary"

Try it as template <class E> typename LinkedList<E>::node * LinkedList<E>::getNode(const E &item) since I believe the situation is equivalent (or at least parallel to) this thread.

i'm sorry but i don't understand what you mean by

No, not a problem at all. I just meant that classically people put declarations, defines, etc. in the header file and leave the implementation to a separate .cpp file whereas with templates all of that (declarations, definitions, etc) together has to get lumped in the same .h file with almost all compilers.

thank you for the help..now it works..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.