tags:

views:

77

answers:

1

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

A: 

Yes. But don't take my word for it, try it and see.

OldFart
wrote a quick test .. and you are right.. just wanted to share this that's why asked the question on the SO. :)
SWKK