Templates 使用std::make_共享自己的std::shared_ptr

Templates 使用std::make_共享自己的std::shared_ptr,templates,c++11,shared-ptr,Templates,C++11,Shared Ptr,对于调试情况,我需要实现一个自己版本的共享\u ptr类。当我使用std::shared_ptr时,为了方便起见,我通常使用typedef: typedef std::shared_ptr<myclass> myclassptr; typedef std::shared_ptr myclassptr; 在调试情况下,我希望使用一些额外的调试方法而不是使用typedef扩展共享的_ptr模板,而不是类myclass: class myclassptr : public std::s

对于调试情况,我需要实现一个自己版本的共享\u ptr类。当我使用std::shared_ptr时,为了方便起见,我通常使用typedef:

typedef std::shared_ptr<myclass> myclassptr;
typedef std::shared_ptr myclassptr;
在调试情况下,我希望使用一些额外的调试方法而不是使用typedef扩展共享的_ptr模板,而不是类myclass:

class myclassptr : public std::shared_ptr<myclass>
{
  public:
   // some special tracking methodes
};
class myclassptr:public std::shared\u ptr
{
公众:
//几种特殊的跟踪方法
};
但这给我留下了一个无法编译的cast:

myclassptr mcp=std::make_shared<myclass>();
myclassptr mcp=std::make_shared();
我已经将make_封装在工厂函数中,如:

myclassptr createMyClass()
{
  return std::make_shared<myclass>();
}
myclassptr createMyClass()
{
返回std::make_shared();
}

但是我如何才能获得调试版本呢?

myclassptr
一个构造函数(可能还有赋值操作符),它接受
std::shared\u ptr

class myclassptr : public std::shared_ptr<myclass>
{
  public:
   // some special tracking methodes

    myclassptr(std::shared_ptr<myclass> arg)
      : std::shared_ptr<myclass>(std::move(arg))
    {}

    myclassptr& operator= (std::shared_ptr<myclass> src)
    {
      std::shared_ptr<myclass>::operator=(std::move(src));
      return *this;
    }
};
class myclassptr:public std::shared\u ptr
{
公众:
//几种特殊的跟踪方法
myclassptr(标准::共享参数)
:std::shared_ptr(std::move(arg))
{}
myclassptr&operator=(std::shared_ptr src)
{
std::shared_ptr::operator=(std::move(src));
归还*这个;
}
};

根据你如何使用<代码> MyCalaspTrp/Cux>,你可能或可能不想将构造函数标记为<代码>显式< /C> > ./P>有一个转发到基类的Ccor?@ Xeo UAAA,这就是我忘记的。我必须加上“*-THEGET()”和“但是”,但是我用VC VC++ 2013运行它。Thx@MartinSchlott很抱歉,

get()
部分不应该在那里,这是我代码中的“输入错误”(错误标识符)。它应该返回
myclassptr&
-我已经更新了答案。