P
Pallav singh
Hi All
How to use weak_ptr to break cyclic reference here ?
#include <iostream>
#include <boost/smart_ptr.hpp>
using namespace std;
struct Dad;
struct Child;
typedef boost::shared_ptr<Dad> DadPtr;
typedef boost::shared_ptr<Child> ChildPtr;
struct Dad
{
ChildPtr myBoy;
};
struct CChild
{
DadPtr myDad;
};
// a "thing" that holds a smart pointer to another "thing":
DadPtr parent(new DadPtr);
ChildPtr child(new ChildPtr);
// deliberately create a circular reference:
parent->myBoy = child;
child->myDad = dad;
Thanks
Pallav Singh
How to use weak_ptr to break cyclic reference here ?
#include <iostream>
#include <boost/smart_ptr.hpp>
using namespace std;
struct Dad;
struct Child;
typedef boost::shared_ptr<Dad> DadPtr;
typedef boost::shared_ptr<Child> ChildPtr;
struct Dad
{
ChildPtr myBoy;
};
struct CChild
{
DadPtr myDad;
};
// a "thing" that holds a smart pointer to another "thing":
DadPtr parent(new DadPtr);
ChildPtr child(new ChildPtr);
// deliberately create a circular reference:
parent->myBoy = child;
child->myDad = dad;
Thanks
Pallav Singh