X
XP
I was wondering if this is possible. As I currently use something like this:
class Ta {
public: Type * pType;
Ta();
~Ta();
}
// Constructor - initialize pType
Ta::Ta() {
pType = new Type();
}
// destroy pType
Ta::~Ta() {
delete pType;
}
So... how would you do it with std::auto_ptr so that it doesn't go out of
scope? Or maybe I should go with boost::shared_ptr with one additional
reference that won't go out of scope. I could place std::auto_ptr<Type>
pType(new Type()); but that would of course go out of scope as soon as
constructor has finished. Any way to force it to stay defined until
destructor?
The point is to avoid new and delete and use auto_ptr or something similar
in this example class.
class Ta {
public: Type * pType;
Ta();
~Ta();
}
// Constructor - initialize pType
Ta::Ta() {
pType = new Type();
}
// destroy pType
Ta::~Ta() {
delete pType;
}
So... how would you do it with std::auto_ptr so that it doesn't go out of
scope? Or maybe I should go with boost::shared_ptr with one additional
reference that won't go out of scope. I could place std::auto_ptr<Type>
pType(new Type()); but that would of course go out of scope as soon as
constructor has finished. Any way to force it to stay defined until
destructor?
The point is to avoid new and delete and use auto_ptr or something similar
in this example class.