我正在清理掉我的C++知識並嘗試在此處編寫程序。從派生類構造函數初始化受保護的數據成員
class Quad{
public:
Quad(){}
protected:
vec _topLeft, _topRight, _bottomLeft, _bottomRight;
};
class IrregularQuad : public Quad{
public:
IrregularQuad(vec topLeft, vec topRight, vec bottomLeft, vec bottomRight)
: _topLeft(topLeft), _topRight(topRight), _bottomLeft(bottomLeft), _bottomRight(bottomRight)
{}
};
我以上Dervied類承包商得到一個編譯錯誤說: 成員初始化_topLeft沒有指定非靜態數據memeber或基類(類似的錯誤對其他成員的工作)
我無法理解發生什麼事情。難道我不能使用Initalizer列表或其他東西來初始化受保護的成員嗎?
什麼是'vec'? –
'vec'是我爲矢量(x,y,z)定義的另一個類 – user1240679
[派生構造函數中訪問基本成員的問題]的可能重複(http://stackoverflow.com/questions/2947583/problem-accessing-base - 成員在派生構造函數) –