If I create an object on the stack and insert it into the list, then the object loses scope (outside the for loop in the example below) will the object still exist in the list? If the list still contains the object, then the data is now invalid / possibly corrupted?
Please let me know and please explain the reasons.
Thanks JBU
class SomeObject{
public:
AnotherObject x;
}
void someMethod()
{
std::list<SomeObject> my_list;
for(int i = 0; i < SOME_NUMBER; i++)
{
SomeObject tmp;
my_list.push_back(tmp);
}
my_list.front();
}
EDIT: so what if it were std::list<SomeObject*> my_list; instead of a list ... in this case will it be invalid?
source
share