templates - Own std::shared_ptr with std::make_shared -



templates - Own std::shared_ptr with std::make_shared -

for debug situation need implement own version of shared_ptr class. typical when utilize std::shared_ptr utilize typedef convenience:

typedef std::shared_ptr<myclass> myclassptr;

in debug situation want extend shared_ptr template, not class myclass, additional debug methods instead of using typedef:

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

but leave me cast at, not compile:

myclassptr mcp=std::make_shared<myclass>();

i encapsulate make_shared in mill funktion like:

myclassptr createmyclass() { homecoming std::make_shared<myclass>(); }

but how can debug version?

give myclassptr constructor (and assignment operator too) accepts std::shared_ptr:

class myclassptr : public std::shared_ptr<myclass> { public: // 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)); homecoming *this; } };

depending on how utilize myclassptr, may or may not want mark constructor explicit.

templates c++11 shared-ptr

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -