Maybe there is the same question but I haven't found it.
I have following code:
class MBase {
public:
~MBase() { cout << "Base destructor\n" << endl; }
};
class MF: public MBase {
public:
~MF() { cout << "MF Destructor" << endl; }
};
class MS: public MBase {
public:
~MS() { cout << "MS Destructor" << endl;}
};
int main() {
unique_ptr<MBase> ptr1 = unique_ptr<MF>(new MF());
unique_ptr<MBase> ptr2 = unique_ptr<MS>(new MS());
return 0;
}
And there is output
Base destructor
Base destructor
Isn't it right? Why derived destructors weren't called? What I have to do to fix that?