c++ - auto_ptr or shared_ptr -



c++ - auto_ptr or shared_ptr -

in c++03 environment, utilize auto_ptr or (boost) shared_ptr homecoming resource function? (where in c++11 1 naturally utilize unique_ptr.)

auto_ptr<t> f() { ... homecoming new t(); }

or

shared_ptr<t> f() { ... homecoming new t(); }

auto_ptr has quite pitfalls (not to the lowest degree it's construction awfully buggy on msvc 2005 have use), shared_ptr seems overkill ...

in c++03, utilize either bare pointer or auto_ptr , allow caller decide on ownership strategy.

note 1 of pitfalls of smart pointers covariance not apply them, meaning can override base* f() derived* f() cannot override std::x_ptr<base> f() std::x_ptr<derived> f(); , in case have no selection utilize simple pointer.

c++ shared-ptr auto-ptr visual-c++-2005

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -