Using templates within a class
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()
{
}
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.
'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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement