Vote count:
0
Is it safe to remove the only shared_ptr reference to itself inside a method? Something like the following. If two objects, one of class A and the other of class B, points to each other via their pB_ and pA_. Suppose pB_ is the only reference to the object of class B. Then I call A::method() on the object of class A. Will there be any problem?
#include <iostream>
using std::shared_ptr
class B;
class A {
public:
void method() {
pB_->method();
}
shared_ptr<B> pB_;
};
class B {
public:
void method() {
pA_->pB_.reset();
}
shared_ptr<A> pA_;
};
asked 1 min ago
Is it OK to remove shared_ptr reference to itself
Aucun commentaire:
Enregistrer un commentaire