-
Shared Objects in C++
HI
i was writing a piece of code in which i have some problems with shared objects.
I have 2 classes say class A and class B
i want that all objects of class B have a common class A object.
ie one class A object shared by all Class B objects.
I cannot use a static class A object as a member of class B because i need to packge the code as a dll.
Any suggestions on this
Rajan
-
Use a pointer instead of an object. Have each B object contain a pointer to A, and make sure that the pointers in all Bs are bound to the same instance. The Singletone pattern is exactly what you need: http://www.devx.com/DevX/LegacyLink/9472
-
a = new A; // (contains class B)
b = new A; // (contains class B)
c = new B;
a.bref = c; // Two references referring to the same reference object.
b.bref = c;
and so on...
EVAC