Fadecomic
Fadecomic

Reputation: 1268

Do stl vectors inside stl vectors go out of scope when the vector is cleared?

In this code:

class myClass
{
    ...
    vector<myThing> thing(10);
    vector<myStuff> stuff(10);
    ...
}

vector<myClass> vecClass(10);
...
vecClass.clear();  /// calls destructor on myClass instances

Each element of vecClass holds 10 element vectors of thing and stuff. When clear() is called, does that make thing and stuff go out of scope, and thus be destroyed properly? Or is there something explicit that I have to do?

Upvotes: 3

Views: 290

Answers (1)

Thomas
Thomas

Reputation: 181735

Yes, their destructors will be called. There is nothing else you need to do here.

Upvotes: 11

Related Questions