先看代码
#include<iostream>
using namespace std;
class Employee
{
private:
string name;
string number;
double basicSalary;
public:
Employee()
{
name = "name";
number = 1234;
basicSalary = 3000;
}
void input()
{
cout << "Name:";
cin >> name;
cout << "Number:";
cin >> number;
cout << "BasicSalary:";
cin >> basicSalary;
}
double pay()
{
return basicSalary;
}
void print()
{
cout << "Name:" << name << '\t' << "Number:" << number << '\t' << "BasicSalary:" << basicSalary;
cout << '\t' << "Sum_Salary:" << pay() << '\t';
}
};
class Salesman :public Employee
{
private:
double sales;
double commrate;
public:
Salesman() :Employee()
{
sales = 3241;
commrate = 2315;
}
void input()
{
Employee::input();
cout << "Sales:";
cin >> sales;
cout << "Commrate:";
cin >> commrate;
}
double pay()
{
return (Employee::pay() + sales * commrate);
}
void print()
{
Employee::print();
cout << "Sales:" << sales << '\t' << "Commrate:" << commrate << '\t';
}
};
class Salesmanager :public Salesman
{
private:
double jobSalary;
public:
Salesmanager() :Salesman()
{
jobSalary = 2000;
}
void input()
{
Salesman::input();
cout << "JobSalary:";
cin >> jobSalary;
cout << endl;
}
double pay()
{
return (Salesman::pay() + jobSalary);
}
void print()
{
Salesman::print();
cout << "JobSalary:" << jobSalary << endl;
}
};
int main()
{
cout << "基本员工" << endl;
Employee emp1;
emp1.input();
emp1.print();
cout << endl;
cout << "销售员" << endl;
Salesman emp2;
emp2.input();
emp2.print();
cout << "销售经理" << endl;
Salesmanager emp3;
emp3.input();
emp3.print();
}
问题:
为什么我输出的Sum_Salary一直等于basicSalary,而不是我派生类成员函数 pay中的返回值
是我的继承中出现了什么问题吗