-2

i'm trying to return a reference/pointer node from a linked list that i create. here is my class and the method Return node, when i pass a value it does a look up in my list, but the compiler is giving me three errors: 1-error C2143: syntax error : missing ';' before '*' 2-error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 3-error C1903: unable to recover from previous error(s); stopping compilation

Can somebody help me with that? Thank you very much!

template <class Type>
class LinkedList
{
private:
struct Node
{
    Type value;
    Node* next;
};
    Node* list;
public:

//Other functions here

Node* FindNode(Type);

};

template <class Type>
LinkedList<Type>::Node* LinkedList<Type>::FindNode(Type _value)
{ 
Node* q = first;
while(q != NULL && q->value != _value)
    q = q->next;
return q;
}
Hille
  • 35
  • 1
  • 2
  • 6

1 Answers1

0

Since you have a dependent, qualified name, you should use the typename disambiguator:

    template <class Type>
    typename LinkedList<Type>::Node* LinkedList<Type>::FindNode(Type _value)
//  ^^^^^^^^

Otherwise the compiler won't parse Node as the name of a type.

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
  • thank you very much. How can i instance from that class in another class? I'm doing : LinkedList list; but it does't work, is giving me Error LNK2001 and LNK2019. – Hille Apr 28 '13 at 17:11
  • @user2177428: I'm not sure I understand. Where are you doing that? What are the error messages? Also, make sure the definitions of your class template member functions are in the same header file as the definition of the class template `LinkedList` itself - usually template definitions belong to headers – Andy Prowl Apr 28 '13 at 17:15
  • yes, that was the problem, i had my methods in a different file. If i put all methods in the same header file it works like a charm, but what i have to do to have my methods in other cpp file? I tried put template before every method in the header file but it does't work. I thank you very much because you helped me a lot. – Hille Apr 28 '13 at 17:42
  • @user2177428: You're welcome. If the answer above solved the problem in the question, please consider marking it as accepted :) Regarding what is needed to have template definitions in `.cpp` files - you need so-called "explicit instantiations". You can read more about it [here](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file). – Andy Prowl Apr 28 '13 at 17:46