Q-bertsuit
Q-bertsuit

Reputation: 3437

Should I still use smart pointers if only std::auto_ptr i available?

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?

Upvotes: 3

Views: 201

Answers (3)

Bathsheba
Bathsheba

Reputation: 234715

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.

Upvotes: 3

Xeonacid
Xeonacid

Reputation: 11

Maybe you can use std::tr1::shared_ptr.

tr1: C++ Technical Report 1 - Wikipedia

Upvotes: 1

Alex Celeste
Alex Celeste

Reputation: 13370

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.

Upvotes: 7

Related Questions