Suppose I have a class:
class Test{
public:
std::vector<int*> foo;
Test(){
int * x = new int(5);
int * y = new int(10);
foo.push_back(x);
foo.push_back(y);
}
~Test(){
for(int i = 0; i < foo.size(); i++){
delete foo.at(i);
}
}
void reAssignTest(){
Test test2;
*this = test2;
}
};
int main(){
Test test;
}
I noticed that my for loop in my deconstructor never runs b/c the size of foo is 0 when the deconstructor gets called once my original 'test' instance gets replaced by test2. Thus the int variables in the heap never get destroyed. Is this because the vector has its deconstructor called before my code in my deconstructor runs?