class Base {
public:
Base() {
std::cout << "Base::ctor" << std::endl;
}
~Base() {
std::cout << "Base::dtor" << std::endl;
}
};
class Derived : public Base {
public:
Derived() {
std::cout << "Derived::ctor" << std::endl;
}
~Derived() {
std::cout << "Derived::dtor" << std::endl;
}
};
int main(int argc, char** argv){
std::unique_ptr<Base> b = std::make_unique<Derived>();
}
The correct output is:
Base::ctor
Derived::ctor
Base::dtor
But according to me, it should be:
Base::ctor
Derived::ctor
Derived::dtor
Base::dtor
Can someone explain why this order of output ?? Why does it not follow the intended order ?