#### Archived

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

# STL::list

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

## 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 on other sites
Store pointers instead of objects themselves:

list<CObject*> children;

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

##### 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 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.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 17
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631758
• Total Posts
3002155
×

## Important Information

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!