The project that I'm currently working on uses an older compiler that does not support C++11, so no unique_ptr or shared_ptr is available.
Should I use the now deprecated auto_ptr instead or should I just drop using smart pointers altogether?
The project that I'm currently working on uses an older compiler that does not support C++11, so no unique_ptr or shared_ptr is available.
Should I use the now deprecated auto_ptr instead or should I just drop using smart pointers altogether?
If you can use Boost, it has provided shared_ptr
since long before it was standardized in C++11, so a suitably old version of Boost should be able to provide this in an '03-compatible way.
I'd recommend you move away from std::auto_ptr
as it's scheduled for deprecation.
But I would shy away from using bare pointers.
Pre C++11, you could use the smart pointer classes available in Boost (www.boost.org). Failing that, you could roll your own versions with a view to removing them once they are available in your standard library. Note that std::shared_ptr
is easier to implement than std::unique_ptr
, in the latter case I believe you'd have to give up portability since it requires move semantics to implement correctly.