成员函数void readPayInfo()在类BonusEmployee中重新定义。它现在返回数据成员基本工资的值加上数据成员奖金的值
class Employee
{
public:
//constructors here
void readPayInfo()
{cin >> basePay;}
private:
double basePay;
};
class BonusEmployee : public Employee
{
public:
//constructors here
void readPayInfo()
{cin >> basePay >> bonus;} // NULL!
private:
bonus;
};
如何从父类访问basePay?
答案 0 :(得分:0)
由于您选择将Employee::basePay
设为私有,因此无法从子类直接访问它。我认为你有两个选择:
Employee
或Employee::basePay
的可见度更改为protected
。