1 2
|
std::auto_ptr<char> p; // Defaults to 0 (NULL)
return SomeOtherFunction( p.get() );
|
I presume some other code exists between the declaration of p and
the call to SomeOtherFunction to initialize/allocate p, otherwise
SomeOtherFunction would have to initialize it and return it by taking
p by non-const reference. If that is the case, then SomeOtherFunction
would have to be changed to take a std::auto_ptr<> by non-const
reference (and then don't call it with p.get(); just p).
std::auto_ptr<> is declared in <memory>
std::auto_ptr<> may not be exactly what you want; from the looks
of it, you might be more interested in a boost::scoped_ptr, which
is declared in <boost/smart_ptr.hpp> but requires the boost libraries.