How does any object you create knows it goes out of scope? There is nothing magical about vector -- all objects have a destructor that gets invoked automatically when the object goes out of scope.
Do you know what a destructor is and when it's called? If not, I suggest you read up on basic C++ fundamentals.
All objects that are declared have a scope, block scope, function scope, file scope, etc. When the object goes out of scope, the destructor is automatically invoked. The object doesn't "know" when it is or is not in scope, as it doesn't need to. Everything is taken care of by the language.
Do you understand this concept?Code:void f()
{
int a;
} // when this function is done, a is no longer in scope.
Regards.
Paul McKenzie

