Lets say I have the following function:
void testFunction ()
{
int i;
Teapot teapot;
Teapot * teapot;
vector1.push_back (i);
vector2.push_back (teapot);
vector3.push_back (&teapot);
}
If each of those vectors is declared globally and holds the proper data type, will all of these vectors contain the data created in the function after the function executes?
I read that int i would be created on the stack and would only exist in the function scope. Does the same apply for Teapot teapot? If vector1 does contain int i after the function executes, how would the int be added to the vector if it is destroyed after the function executes?
I also read that Teapot * teapot is stored on the heap which is why vector3 will contain &teapot after execution. Do I have my heap and stack info correct?
Thanks!
This post has been edited by rmetzger: 03 November 2010 - 11:23 AM

New Topic/Question
Reply




MultiQuote




|