I have the following classes
class a {
std::shared_ptr<b> b_ref;
public:
a(std::shared_ptr<b> b_ref) : b_ref(b_ref) {}
};
class b {
std::shared_ptr<a> a_ref;
public:
b(std::shared_ptr<a> a_ref) : a_ref(a_ref) {}
};
Now I want to create two objects that reference each other is there any way to do this? I think with c-style pointers I could achieve this. Does it work with shared pointers as well? I tried the reset() and swap() methods without any success.
std::shared_ptr<a> a_ref;
std::shared_ptr<b> b_ref;
a_ref = std::make_shared<a>(b_ref);
b_ref = std::make_shared<b>(a_ref);
Did not work.