problem with template and inner struct

Hello, I'm having a problem with the following code:

1
2
3
4
5
6
7
8
9
10
11
template <class T> class List
{
   struct Node
   {
        struct Node *next;
        T* data;
        struct Node *prev;
   }*first, *last;

   node* getNodeAt(int);
}


This "getNodeAt(int)" method that iterates through the list and return a pointer to the node at the position entered on the parameter.
Here is the implementation signature:

 
template <class T> List<T>::Node* List<T>::getNodeAt(int index) { ... }


I'm using MingW on Windows 7 and I'm getting the follow error from the compiler:
expected constructor, destructor, or type conversion before '*' token


I've looked some similar code, but without templates, and tried removing it from my code and it worked, however that's not what I want.

Do you have any idea what could it be?
Don't forget that c++ is case sensitive :P

This -> node* getNodeAt(int); should be -> Node* getNodeAt(int);

EDIT: Also, make sure you put a semicolon at the end of you class definition, and have all the template stuff (declarations and implementation) inside a header.

EDIT 2: Ok, I found it. You have to use the typename keyword:

template <class T> typename List<T>::Node* List<T>::getNodeAt(int index) { ... }

It should be ok now.
Last edited on
sorry, I couldn't copy and paste the code, it was just a typo, this is correct in the original code.

EDIT: Thank you very much, that worked well (I didn't even know that that keyword existed).
Last edited on
Topic archived. No new replies allowed.