我有一个父类:雇员有两个继承类:小时和工资 在父类中,我重载了< <,所以它会输出员工的所有变量值。我需要创建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