Archived

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

Jimfing

STL::list

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 {
public:
    // 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