I have a classes that contains data in form of MyObjects like class A. I wish to Monitor the data in the MyObject objects. So I created a IMonitorable class and derived all my storage classes that contains the MyObjects from IMonitorable. Add added the IMonitorable class as a friend to my monitoring class.
class IMonitorable
{}
class a : public IMonitorable
{
protected:
struct myData
{
MyObject a;
MyObject b;
...
} data;
}
class Monitor
{
public:
friend IMonitorable;
AddData(a& stroage);
AddObject(MyObject& obj);
}
This worked fine while I had one storage class with a known myData struct. I called
AddData(InstanceOfA);
and added MyObject a,b,.. to my monitoring mechanism.
Now I have several storage classes and I don't want to write an AddData method for all storage classes. I thought of having a AddObject method to be able to have a single point suitable for all storage classes.
AddObject(InstanceOfA.data.a);
AddObject(InstanceOfA.data.b);
...
But if I call this somewhere in my code gcc throws the error data.a is protected, what is right.
Is there a way to add a reference or a pointer of the protected MyObject to the Monitor without the knowledge of the structure of the storage class?