Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 5752 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

Hi, I''m trying to use STL:list and it works like a charm for having a list of my 3d object class. However, I want to have children of that class, so I thought I could do something like this:
class CObject {
    // child objects:

    list<CObject> child;  // compiler doesn''t like this

// etc


// later on...

// parent objects:

list <CObject> objects;  // this obvioulsy works fine

When I try to compile this, i get: error C2079: ''_Value'' uses undefined class ''CObject'' However, if I use STL::vector instead of list, it works fine. But I want to use list since pointers are invalidated when removing/adding elements from vector. I know I can use a linked list (already done so), but since stl::list is availible, I thought I would use it. Thanks for any help James

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Store pointers instead of objects themselves:

list<CObject*> children;

and it''s std::list, not stl::list

Share this post

Link to post
Share on other sites
Also just to note. The compiler works out the size of objects that would be created by a class - at compile time. Even though the list might theoretically be empty it is quite likely that in the definition of the list there will be the use of the CObject constructor, which to be validly define, needs to know the size of a CObject. So there is a cycle of ''to define a CObject it needs to know the size of a CObject''. This can be broken by only using pointers. They have a well defined size at compile time.

Share this post

Link to post
Share on other sites
LOL, woops, yeah I meant std, not stl. Was early in the morning!

Thanks for the reply guys, using pointers does work.

Share this post

Link to post
Share on other sites

  • 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!