There's also such a thing as move constructors, so that you can pass ownership to somewhere else and have it be deleted there.
For instance,
std::unique_ptr<X> f () {
return std::make_unique<X>();
}
void h (std::unique_ptr<X> x) {
x->doSomething();
// x is released after this function returns
}
void g () {
auto x = f();
h(std::move(x));
}
For instance,