A singleton class inside a library ?

I am creating this library where the structure is like that :

Partent : - available to the user
class1: can perform requests from parent (not a subclass)
class2: can perform requests from parent (not a subclass)

The thing is , all these classes(1,2), and parent, should share some variables during the time they run,
so if there is a floats array declared in the parent, all other classes should be able to assign values to it, or read it any time.

Is there a simple way of doing this ? do I have to use a singleton to share data ?

If I am going to pass this array between them, its going to be a really big mess .


There are many ways to do that, and a singleton class is about the last one I would choose. If those classes exist purely to "serve" the "parent", then create the array within the parent, and pass a pointer to the array to the constructors for the two classes, or simply provide accessor functions within the parent to modify the array. Create a "factory" method within the parent to create instances of the two classes, so those instances are passed to the user already knowing how to access the array.

Regards, Ray L.

Another option is a C++ friend declaration. In C++, friends can see each other's private parts. (old programming joke)

Thanks Ray, and thanks for the joke.

But if parent class create an instance of class1 , how can class1 "see" (being exposed) to the parent class variables? (parent can see class1, not the opposite?)