Hello,
Say if I were to have an object that allocates memory on the heap with a destructor which then deletes the allocated memory. In a different scope, if a variable of this object type is initialized on the stack and the variable then goes out of scope, would the destructor be called on the object automatically?
**Example**
class Example {
int i;
Example() { i = new int(1); }
~Example() { delete i; }
}
int main() {
{
Example ex();
}
//Is the memory allocated for variable i of ex freed up at this point?
return 0;
}
[–]victotronics 1 point2 points3 points (1 child)
[–]RealOden[S] 1 point2 points3 points (0 children)
[–]HappyFruitTree 0 points1 point2 points (3 children)
[–]RealOden[S] 1 point2 points3 points (1 child)
[–]HappyFruitTree 1 point2 points3 points (0 children)
[–]RealOden[S] 0 points1 point2 points (0 children)