-
Problem with templates
hi all,
i have the following code:
PHP Code:
#include <iostream.h>
typedef struct node * ptr;
template <class T> struct node{
ptr next;
T item;
};
int main()
{
// do nothing
system("PAUSE");
return 0;
}
when i try to run it i get this error:
[C++ Error] stack.cpp(4): E2356 Type mismatch in redeclaration of 'node'
i think its from the typedef but i dunno how to fix it!
thanks for any help.
-
As your typedef will likely be local to the node....keep it local
Code:
#include <iostream.h>
template<class T>
struct node{
typedef struct node* ptr;
ptr next;
T item;
};
int main()
{
// do nothing
system("PAUSE");
return 0;
}
-
No its not local, im gonna use it inside another class which i haven't written yet!
Any ideas?!
-
You can use typedefs inside classes:
node<T>::ptr