typedef with a generic structure
I'm trying to make a generic linked list using a structure.
1 2 3 4 5 6 7 8
|
template<class T>
struct LinkedList
{
T i;
LinkedList *link;
};
typedef LinkedList* LinkedListPtr;
|
I'm using Dev-C++'s MinGW compiler. It keeps giving me this error:
expected init-declarator before '*' token
expected `,' or `;' before '*' token
|
You forget the template parameters.
LinkedList*
is not a type, but LinkedList<something>*
is
Hello, I edited my code to:
1 2 3 4 5 6 7 8 9
|
template<class T>
struct LinkedList
{
T i;
LinkedList<T> *link;
};
template<class T>
typedef LinkedList<T>* LinkedListPtr;
|
But the compiler outputs:
template declaration of `typedef struct LinkedList<T>*LinkedListPtr'
|
It didn't work when I tried doing this either:
|
typedef LinkedList<T>* LinkedListPtr<T>;
|
You can't template a typedef declaration.
What you can do :
1 2 3 4 5 6 7
|
template<class T>
struct LinkedList
{
T i;
LinkedList<T> *link;
typedef LinkedList<T>* Ptr;
};
|
Thank you very much.
Topic archived. No new replies allowed.