Consider the following case:
typedef boost::shared_ptr<B> BPtr;
class A
{
public:
A() { b_ptr = BPtr(new B); }
void a_func() { C::c_func(b_ptr); }
private:
BPtr b_ptr;
}
class B
{
public:
B() { b_ptr = BPtr(this); }
void b_func() { C::c_func(b_ptr); }
private:
BPtr b_ptr;
}
class C
{
public:
static void c_func(BPtr b_ptr) { }
}
Is it possible to create an instance of shared_ptr with this?
Is it possible to have two shared_ptr objects pointing to the same object? (for example, A :: b_ptr and B :: b_ptr)
If one of these two goes out of scope, is instance B deleted?
I assume that I am doing something fundamentally wrong.
I also thought about using b_ptr dependency injection on constructor B, but that seems very wrong too.
UPDATE:
- A, B C:: c_func. , C B, .
:
- , C , BPtr A, B, .
- C A B C, BPtr C ctor.