I am having a hard time trying to understand why the variable engineNum
is inaccessible from within the function in the class Pickup
. My basic understanding is, if the class is inherited the private variables should be accessible. This isn't the case I am finding:
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++; };
}
};