Using templates within a class

Started by
3 comments, last by djamelh 18 years, 10 months ago
Hello everyone I have a class defined in node.h and i want vector<CNode> m_lNodeList; to be a member of it but the compiler doesnt like this. Any ideas on how to fix it? The compiler gives me "error C2143 : syntax error : missing ';' before '<'" and some other garbage. I basicaly want my node class to contain a list of other node classes. I thought I'd use the vector template but maybe this isnt the best way of doing it. Does anyone know a better idea? Thanks. //node.h #include <vector> class CNode { public: CNode(); virtual ~CNode(); private: vector<CNode> m_lNodeList; // this line causes an error }; //node.cpp #include "node.h" CNode::CNode() { } CNode::~CNode() { }
Advertisement
You are missing a 'std::' infront of 'vector'.
'std::vector<CNode>' should work.
Or type 'using namespace std' above the class definition somewhere.

But CNode is probably going to be a base class for other specialized nodes that you want to use in your scene graph, right? So it's probably a better idea to have a list of 'CNode *' instead. That way your list can store instances of all classes that derives from CNode.
Sorry i didnt include all the code so as only the main problem is higlighted. I am using namespace std, and some of the functions take advantage of the vector class by calling size() and using the iterators. I dont need any specialized nodes just the one class. I was thinking of just using *CNode but the Vector class would make life much easier.
Well, the code you posted generates error C2143 exactly as you said. Adding 'std::' resolves that error. So do you still have a problem with the code? In that case, post more of it.
Sorry my bad you're right, thanks a lot my code compiles now.

This topic is closed to new replies.

Advertisement