我有一個父類:僱員有兩個繼承類:小時和工資 在父類中,我重載了< <,所以它會輸出員工的所有變量值。我需要創建3名新員工:2小時和1工資,但我的構造函數似乎沒有正常工作。程序會編譯,但是當我調用Hourly構造函數時,程序停止工作(堆棧溢出?)。下面是一些代碼:繼承類中的構造函數C++
class employee
{
friend ostream& operator<<(ostream& out, const employee& emp);
public:
employee();
employee(string id, string fname, string lname, string bDate, string hDate, double pay);
~employee();
void setEmpId(string id);
string getEmpID();
void setFirstName(string name);
string getFirstName();
void setLastName(string name);
string getLastName();
void setBirthDate(string birthDate);
string getBirthDate();
void setHireDate(string hireDate);
string getHireDate();
void setPayRate(double rate);
double getPayRate();
protected:
string employee_id;
string first_name;
string last_name;
string birth_date;
string hire_date;
double pay_rate;
};
這是我的父類,這裏是我的兩個繼承的類:
class Hourly : public employee
{
public:
Hourly(string fname, string lname, string bdate, string hdate, double rate, string id)
{
int random = rand() % 1000;
this->employee_id=id;
this->first_name=fname;
this->last_name=lname;
this->birth_date=bdate;
this->hire_date=hdate;
this->pay_rate=rate;
}
};
薪水階級本質上是同樣的事情的現在。這裏就是我試圖製作我的小時工:
employee empOne = Hourly("Brian", "Finn", "1/12/1995", "1/12/2015", 7.25, "1215");
cout << empOne;
我知道,它從來沒有得到過去的構造,因爲我試圖清點測試和程序從不那麼遠。
這是不正確的實際接受抄襲答案。 – g24l