object vector, identifier

Inside of my controller class (Framework) I have a nested class called DynamicObject. I have a vector of DynamicObject pointers (m_vpDynamicObjects) and I need to remove a specific type of DynamicObject, which, ideally, would be determined by a unique identifier. My trouble isn't with removing the object, but by creating the ID for each object in the vector to begin with.

I would like to generate the ID within the DynamicObject constructor, i.e., whenever a new one is created, it generates an ID for itself based on the size of m_vpDynamicObjects - the first one added to the vector would have ID 1, the second would have ID 2, etc.

I'm not quite sure how to go about getting the size of the vector (declared within the outer class) from the constructor of the nested class. I really don't want to get the vector size every time I push a new DynamicObject into the vector (which is a lot) or pass a base class pointer to each object. I can think of a few hacky ways of doing this, but I was wondering what the most efficient way is?

class Framework
     class DynamicObject
          int ID;

          DynamicObject(){ ??? }

     vector<DynamicObject*> m_vpDynamicObjects;
Why does its ID need to match its index in the vector? When you remove it, you'd have to update the IDs of all the ones after it.

A better solution is to just have a static next_id variable in the class, and the instance id variable gets initializes from next_id++.
Ahh I didn't even think of adding another variable to the base class for some reason. Thanks.
Topic archived. No new replies allowed.