I have a parent class: employee with two inherited classes: Hourly and Salary In the parent class I overloaded << so it will output all the variable values from the employee. I need to create 3 new employees: 2 Hourly and 1 Salary, but my constructors don't seem to be working correctly. The program will compile but when I call the Hourly constructor the program stops working (stack overflow?). Here's some code:
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;
};
This is my parent class and here are my two inherited classes:
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;
}
};
The Salary class is essentially the same thing as of right now. Here's where I try to create my Hourly employee:
employee empOne = Hourly("Brian", "Finn", "1/12/1995", "1/12/2015", 7.25, "1215");
cout << empOne;
I know that it never gets past the constructor because I have tried to cout tests and the program never makes it that far.