[英]what happens when you copy vector<boost::share_ptr> to another vector
Do we get multiple copies of the pointers yet the data members are still being shared? 我们是否获得了多个指针副本,但数据成员仍在共享中?
boost::shared_ptr<string> a1(new string("Hello"));
vector<boost::shared_ptr<string> > a;
a.push_back(a1);
vector<boost::shared_ptr<string> > b;
b = a;
cout<<a[0]->c_str()<<b[0]->c_str()<<endl;
a1->append(" World");
cout<<a[0]->c_str()<<b[0]->c_str()<<endl;
Output: HelloHello Hello WorldHello World 输出:HelloHello Hello WorldHello World
Yes. 是。 But don't take my word for it, try it and see.
但是,请不要相信我,尝试一下,看看吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.