Jump to content
  • Advertisement
Sign in to follow this  
djamelh

Using templates within a class

This topic is 4842 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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!