开发者

Shared pointers: pointer to pointer

Common pointers allows you to create pointer to pointer:

void foo(Object **o) {}

int main()
{
   Object * o = new Object();
   foo(&a开发者_如何学运维mp;o);
}

Is there an analogous construction for shared_ptr?

void foo(std::shared_ptr <Object> *o) {}

int main()
{
   std::shared_ptr <Object>  o(new Object());
   foo(&o);
}


Without testing this, I'm pretty sure you'd want:

shared_ptr<shared_ptr<T> > o(new shared_ptr<T>(new T()));

Edit: forgot the "new" after the first '(', and fixed non-standard use of >> in a template definition. (at least, not standard until C++0x)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜