class Base
{
protected:
int data;
public:
virtual int getData() { return data; }
virtual void setData(int value) { data = value; }
};
class Child : protected Base
{
public:
void setData(int value)
{
Base::setData(value);
cout << "Data is set.\n";
}
};
class Worker
{
private:
Child obj;
public:
void setGlobalData(int val)
{
obj.setData(val); // This is normal
}
int getGlobalData()
{
return obj.getData(); // Line 140, Error
}
};
Error during compiling of file with Worker class:
Base.hpp: In member function ‘int Worker::getGlobalData()’:
Base.hpp:22:19: error: ‘virtual int Base::getData()’ is inaccessible
Worker.cpp:140:34: error: within this context
Worker.cpp:140:34: error: ‘Base’ is not an accessible base of ‘Child’