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)
精彩评论