|
-
August 7th, 2010, 05:47 PM
#19
Re: About vectors
 Originally Posted by ProgrammerC++
How does a vector know it goes out of scope?
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.
Code:
void f()
{
int a;
} // when this function is done, a is no longer in scope.
Do you understand this concept?
Regards.
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|