Kopieren boost::shared_ptr

typedef boost::shared_ptr<SomeData> data_ptr;
data_ptr cached_ptr;   //class member 
bool someWork(data_ptr& passed_ptr)
{
  //must copy passed_ptr = cached_ptr under some conditions
  //without pointing at the same memory 
  //I saw somewhere that I should do 
  //passed_ptr.reset(new SomeData(???))
  //I don't have a "reset" on passed_ptr
}

Ich schaute Dokumentation;

kopieren und konvertieren von Konstruktoren

shared_ptr(shared_ptr const & r); //never throws
template<class Y> shared_ptr(shared_ptr<Y> const & r); //never throws
Requires: Y* should be convertible to T*.

Effects: If r is empty, constructs an empty shared_ptr; otherwise,
         constructs a shared_ptr that shares ownership with r.

Ich weiß nicht, wie das funktioniert - ist es so ?

passed_ptr = shared_ptr(cached_ptr);

? Wo würde das const hin ? Und was bedeutet es, dass Sie Eigentum zu teilen ? Dann ist es keine Kopie, wenn ich ändern "passed_ptr", die änderung auf "cached_ptr" ?

Kann ich nicht finden, Beispiele... Bitte um Hilfe.

Danke.

InformationsquelleAutor Thalia | 2013-05-07

Schreibe einen Kommentar