#include <memory> struct A {}; struct B : A {}; std::auto_ptr<B> foo() { return std::auto_ptr<B>(new B); } int main() { std::auto_ptr<A> p = foo(); }