#include <memory>
#include <iostream>
struct Foo
{
~Foo() { std::cout << "Foo\n"; }
};
struct Bar : public Foo
{
~Bar() { std::cout << "Bar\n"; }
};
int main()
{
{
std::cout << "shared_ptr:\n";
std::shared_ptr<Foo> f(new Bar()); // prints Bar Foo
}
{
std::cout << "unique_ptr:\n";
std::unique_ptr<Foo> f(new Bar()); // prints Foo
}
}
I2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEZvbwp7CiAgICB+Rm9vKCkgeyBzdGQ6OmNvdXQgPDwgIkZvb1xuIjsgfQp9OwoKc3RydWN0IEJhciA6IHB1YmxpYyBGb28KewogICAgfkJhcigpIHsgc3RkOjpjb3V0IDw8ICJCYXJcbiI7IH0KfTsKCmludCBtYWluKCkKewogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCAic2hhcmVkX3B0cjpcbiI7CiAgICAgICAgc3RkOjpzaGFyZWRfcHRyPEZvbz4gZihuZXcgQmFyKCkpOyAvLyBwcmludHMgQmFyIEZvbwogICAgfQoKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgInVuaXF1ZV9wdHI6XG4iOwogICAgICAgIHN0ZDo6dW5pcXVlX3B0cjxGb28+IGYobmV3IEJhcigpKTsgLy8gcHJpbnRzIEZvbwogICAgfQp9Cg==