Variable inaccessible despite class inheritance?
本问题已经有最佳答案,请猛点这里访问。
我很难理解为什么在类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | class Truck { private: string model; Truck() {}; static int TruckEngineNum; int engineNum; public: Truck(const string& model) { this->model = model; engineNum = TruckEngineNum++; }; string getModel() { return model; } int getEngineNum() { return engineNum; } }; int Truck::TruckEngineNum = 100; class Pickup : public Truck { public: Pickup(const string& model) : Truck(model) { if((engineNum % 2) == 1){ engineNum++; }; } }; |
派生类不能访问
另外,如果您打算将