[odb-users] How to persist cyclic pointers among A->B->C->A?

Justin Huang yohuang at nvidia.com
Mon Oct 14 01:58:35 EDT 2019


Hi,

If I have three classes A, B and C, and A has pointer to object of class B, B has pointer to object of C, and C has pointer to object of A, which is a cyclic pointer relationship.

How should I persist objects a1/a2/b1/c1? E.g., the persistent sequence, and how to avoid persist same objects twice?

// class definitions
class A {
public:
     std::string name_;
     B *b_;
};

class B {
public:
     std::string name_;
     C *c;
};

class C {
public:
     std::string name_;
     A *a;
};

// objects created
A *a1 = new A("A1");
A *a2 = new A("A2");
B *b1 = new B("B1");
C *c1 = new C("C1");

a1->set_b(b1);
a2->set_b(b1);
b1->set_c(c1);
c1->set_a(a1);

thanks,
Justin

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------


More information about the odb-users mailing list