为共享指针参数提供默认值

时间:2013-03-25 18:50:41

标签: c++ shared-ptr

以下代码在VS2010中给出了编译错误,它支持shared_ptr和make_shared函数。为什么以及如何纠正它?

#include <memory>

class A
{
    A(std::shared_ptr<int> p = std::make_shared<int>())   // error is at this line
    {}
};

它显示“make_shared”不是“全局命名空间”的成员。

1 个答案:

答案 0 :(得分:0)

试试这个:

#include <memory>

class A
{
    //A(std::shared_ptr<int> p = std::make_shared<int>())

    A()  
    {std::shared_ptr<int> p = std::make_shared<int>();}
};