這是錯的?我認爲私人成員不是從基類繼承的:錯誤重複:私人成員的繼承?
「類HourlyEmployee的定義沒有提到成員變量名稱,ssn和netPay,但HourlyEmployee類的每個對象都有成員變量namedname,ssn ,和netPay。成員變量名稱,ssn和netPay從Employee類繼承。「
//This is the header file hourlyemployee.h.
//This is the interface for the class HourlyEmployee.
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE_H
#include <string>
#include "employee.h"
using std::string;
namespace SavitchEmployees
{
class HourlyEmployee : public Employee
{
public:
HourlyEmployee();
HourlyEmployee(const string& theName, const string& theSsn,
double theWageRate, double theHours);
void setRate(double newWageRate);
double getRate() const;
void setHours(double hoursWorked);
double getHours() const;
void printCheck();
private:
double wageRate;
double hours;
};
}//SavitchEmployees
#endif //HOURLYEMPLOYEE_H
其他頭文件:
//This is the header file employee.h.
//This is the interface for the class Employee.
//This is primarily intended to be used as a base class to derive
//classes for different kinds of employees.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using std::string;
namespace SavitchEmployees
{
class Employee
{
public:
Employee();
Employee(const string& theName, const string& theSsn);
string getName() const;
string getSsn() const;
double getNetPay() const;
void setName(const string& newName);
void setSsn(const string& newSsn);
void setNetPay(double newNetPay);
void printCheck() const;
private:
string name;
string ssn;
double netPay;
};
}//SavitchEmployees
#endif //EMPLOYEE_H
行了,謝謝! :d – jyim