L
Laurens
Hi,
My C++ is pretty rusty after years of using Java, I can't recall the exact
details of how destructors work.
I know that a class's destructor is automagically called when an instance
goes out of scope(when it unwinds from the stack). However, I can't recall
whether destructors of member fields get called automatically when this
happens.
Example class:
class MyClass {
private:
OtherClass otherClass();
public:
MyClass();
~MyClass();
};
Example usage:
MyClass myClass(); // Object allocated on stack
<myClass goes out of scope>
// What happens here? Does OtherClass::~OtherClass() get called?
Another example usage, this time with new and delete:
MyClass *myClass = new MyClass(); // Allocated on heap
delete myClass; // What happens here? Does OtherClass::~OtherClass() get
called?
Thanks
-Laurens
My C++ is pretty rusty after years of using Java, I can't recall the exact
details of how destructors work.
I know that a class's destructor is automagically called when an instance
goes out of scope(when it unwinds from the stack). However, I can't recall
whether destructors of member fields get called automatically when this
happens.
Example class:
class MyClass {
private:
OtherClass otherClass();
public:
MyClass();
~MyClass();
};
Example usage:
MyClass myClass(); // Object allocated on stack
<myClass goes out of scope>
// What happens here? Does OtherClass::~OtherClass() get called?
Another example usage, this time with new and delete:
MyClass *myClass = new MyClass(); // Allocated on heap
delete myClass; // What happens here? Does OtherClass::~OtherClass() get
called?
Thanks
-Laurens