Inheritance

Hello,
i am hoping to get some help with the following code and the errors that i am getting. i have never written on here before and i am very new to C++. i have a feeling that i am just missing something simple. i have been staring at the screen for too long. Can someone please help me out. thank you in advance

Error C2039 'Benefit': is not a member of 'Employee' =line 313
Error C2228 left of '.setHealthInsurance' must have class/struct/union =line 313
Error C2039 'Benefit': is not a member of 'Employee' =line 314
Error C2228 left of '.setLifeInsurance' must have class/struct/union =line 314
Error C2039 'Benefit': is not a member of 'Employee' =line 315
Error C2228 left of '.setVacation' must have class/struct/union=line 315
Error C2374 'employee': redefinition; multiple initialization =line 318
Error C2664 'Employee::Employee(Employee &&)': cannot convert argument 3 from 'std::string' to 'char' =line 318

[code]
Employee employee = Employee();
employee.setfirstName(fname);
employee.setlastName(lname);
employee.setGender(gender[0]);
employee.setdependents(atoi(dependents.c_str()));
employee.setannualSalary(sal);
employee.Benefit.setHealthInsurance(hinsurance);
employee.Benefit.setLifeInsurance(linsurance);
employee.Benefit.setVacation(vaca);

Benefit ben(hinsurance, linsurance, vaca);
Employee employee(fname, lname, gender, dependents, salary, ben);

employee.displayEmployee();

class Employee
{
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
Benefit benefit;
private:
static int TotalEmployee;
public:
Employee()
{
firstName = "not given";
lastName = "not given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
TotalEmployee++;
benefit = Benefit("", 0, 0);
}
Employee(string first, string last, char gen, int dep, double salary)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
TotalEmployee++;
benefit = Benefit("", 0, 0);
}
Employee(string first, string last, char gen, int dep, double salary, Benefit ben)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
TotalEmployee++;
benefit = ben;
}
Employee(string first, string last, char gen, int dep, double salary, string hinsurance, double linsurance, int vaca)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
TotalEmployee++;
benefit = Benefit(hinsurance, linsurance, vaca);
}
string getfirstName()
{
return firstName;
}
string getlastName()
{
return lastName;
}
char getGender()
{
return gender;
}
static int getNumEmployees()
{
return TotalEmployee;
}
int getdependents()
{
return dependents;
}
double getannualSalary()
{
return annualSalary;
}
void setfirstName(string first)
{
firstName = first;
}
void setlastName(string last)
{
lastName = last;
}
void setGender(char gen)
{
gender = gen;
}
void setdependents(int dep)
{
dependents = dep;
}
void setannualSalary(double salary)
{
annualSalary = salary;
}
double calculatePay()
{
return annualSalary / 52;
}
void displayEmployee()
{
cout << "\nEmployee Information\n";
cout << "\nName: " << firstName << " " << lastName;
cout << "\nGender: " << gender;
cout << "\nDependents: " << dependents;
cout << "\nAnnual Salary: " << fixed << setprecision(2) << annualSalary;
cout << "\nWeekly Salary " << fixed << setprecision(2) << calculatePay();
}
};
Hello christjd,

Welcome to the forum.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

Your code appears to be missing some parts. I do not see main and the first 14 lines would be better found in main not at the beginning of your code.

No where do I see where or how "Benefit" is defined which makes it hard to understand how you are using it.

The line benefit = Benefit(hinsurance, linsurance, vaca); does not make any sense. It looks like "Benefit" is a class that is being constructed the wrong way. And even if it was don the right way you do not set it equal to a variable this way.

Your topic says "Inheritance", but your code shows no attempt at inheritance.

Try posting the whole code so all can see what you have done and smeone ight be ale to figure out what is wrong.

As it is there is not enough to compile and even if I tried it would be full of errors.

Hope that helps,

Andy
Last edited on
Topic archived. No new replies allowed.