i have a basic and simply question.
I have this scenario:
#include <iostream>
using namespace std;
class Inner1
{
public:
~Inner1() {cout << "Inner1 Des\n";};
};
class Inner2
{
public:
~Inner2() {cout << "Inner2 Des\n";};
};
class Base
{
public:
~Base() {cout << "Base Des\n";};
Inner1 inner1;
Inner2 inner2;
};
int main() {
Base base;
return 0;
}
And my console tells me now this:
Base destructor called
Inner2 destructor called
Inner1 destructor called
Is this the normal behavior? Because the functionality for some functions
is already destroyed in my Base Class destructor and the Inner classes rely
on them.
Not recommended workaround:
Just add a "Destroyer" class with object at the first position:
[...]
class Base
{
public:
~Base() {cout << "Base Des\n";};
class Destroyer
{
~Destroyer()
{
//Put the stuff here because this destr will be called last
cout << "Destroyer Des\n";
}
} _destroyer;
Inner1 inner1;
[...]
Thank you for your help