have this code:
void set(list<Person*>* listP){
Person timmy = Person(10);
listP->push_back(&timmy);
}
int main()
{
list<Person*> listP;
set(&listP);
Person* timmy = listP.back();
}
If i understand correct (please correct me) timmy is allocated on the stack , so i cannot count on the values of timmy when i use them in the main. Am i correct? do i need to create timmy like this:
Person* timmy = new Person(10);
in order to create it on the heap and not on the stack ,so it will not be destroyed after method return?
Thank you