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
}
};
錯誤:與工人類文件的編譯過程中派生類功能
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’
如果getData()在基礎中沒有定義,那很可能是問題的根源。 – 2010-10-20 17:57:38
向我們顯示您的真實代碼。 – 2010-10-20 17:57:57
我修復了一個'虛擬'聲明,但我與GMan - 如果這是你的代碼,你缺少'Base :: getData()'的定義 – birryree 2010-10-20 17:57:57