Default value for boost::shared_ptr on class constructor

José Tomás Tocino picture José Tomás Tocino · Dec 20, 2010 · Viewed 7.3k times · Source

Suppose I have class like

class A{
    public:
    A(int a, boost::shared_ptr<int> ptr){
        // whatever!
    }
};

My question is, what's the default value for that ptr? I'd like to be able to create an instance of that class using

A myA(5);

Sure I know I could create another constructor with just one parameter, but I'm looking for something like

A(int a, boost::shared_ptr<int> ptr = WAT?)

Is it possible? Currently I'm using the two-constructors way, but it would be great to do it this way.

Answer

OneOfOne picture OneOfOne · Dec 20, 2010
#include <boost/make_shared.hpp>

A(int a, boost::shared_ptr<int> ptr = boost::make_shared<int>())

Check http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/make_shared.html