Hi, having a variable like this:

vector<Object*>* foo;

does

delete foo;

deallocate the memory occupied by the various Objects or does it deallocate only the vector container?

It will depend on 1. how you created the vector<Object *> and 2. how and when you created the individual <Object>s.

1.
Is foo dynamically allocated, or did you create a vector<Object *>, then assign the vector's reference to foo? If foo was not dynamically allocated, I don't believe delete will even work.

2.
Are the <Objects> created dynamically? In this case, I believe the Object destructors will be called. You're probably better off deallocating them before deallocating the vector itself though, just to be safe.

foo->push_back(new Object)

Or are the objects created then the reference assigned to the vector? In this case, the Object destructors will NOT be called.

Object anObj;
foo->push_back(&anObj);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.