Clarification on templates

Hi,

I have a class mentioned below

template<class TYPE, class ARG_TYPE = const TYPE&>
class SampleList
{
public:
struct Node
{
Node* pNext;
Node* pPrev;
TYPE data;
};
Node * NewNode(Node& pPrev, Node& pNext);
};

template<class TYPE, class ARG_TYPE>
Node * SampleList<TYPE, ARG_TYPE>::NewNode(Node& pPrev, Node& pNext)
{
//My code goes here
//returning node pointer here
}

When I try to complile the code I keep on getting a compliation error as below

error C2143: syntax error : missing ';' before '*'

When I try to return and int or void it gets compiled successfully...I am new to templates Am i doing anything wrong?

Please help,

Thanks in Advance,
M
closed account (S6k9GNh0)
Just in case, could you please indicate which line the error is called on?
struct Node needs to be

1
2
3
4
5
6
struct Node 
{
    struct Node* pNext;
    struct Node* pPrev;
    TYPE          data;
};


because you are trying to use Node as a type before it is declared (it is not declared until the closing brace for the struct is parsed by the compiler).
Topic archived. No new replies allowed.