Sign in to follow this  

Using templates within a class

This topic is 4557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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() { }

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this