Hey guys, having some trouble with my program. I'm getting and error "No operator matches these operands". Not sure how to fix it. Below is my code. Thanks for any help.
#ifndef HEADER_H
#define HEADER_H
#include <string>
usingnamespace std;
class Employee
{
public:
/**
Constructs an employee with empty name and no salary.
*/
Employee();
/**
Constructs an employee with a given name and salary.
@param employee_name the employee name
@param initial_salary the initial salary
*/
Employee(string employee_name, double initial_salary);
/**
Sets the salary of this employee.
@param new_salary the new salary value
*/
void set_salary(double new_salary);
/**
Gets the salary of this employee.
@return the current salary
*/
double get_salary() const;
/**
Gets the name of this employee.
@return the employee name
*/
string get_name() const;
virtualvoid print() const;
private:
string name;
double salary;
};
class Manager : public Employee
{
public:
Manager();
Manager(string name, double salary, string dept);
string get_department() const;
virtualvoid print() const;
private:
string department;
};
class Executive : public Manager
{
public:
virtualvoid print() const;
private:
string department;
};
#endif
Also, it should probably be EmployeeInfo.push_back(new Manager(name, salary, department));
instead of EmployeeInfo[0] = new Manager(name, salary, department);
since EmployeeInfo is initialized to be empty (and operator[] doesn't expand it).
I just deleted the cout statements cause I realized I didn't need them. But now i'm getting another error. unresolved externam symbol "public : virtual void Employee::print(void) const.
Yeah I'm linking fine. I thought the virtual made it so I don't have to have a print function? My professor is pretty horrible at teaching us anything so I'm sorry if I don't sound so learned in it. She didn't say anything on the assignment about implementing a print method in the Employee class.
Yea i can see what you're trying to do, but at the end of the day you have a Employee class that does not inherit from anything, you've declared prototype for print() in your header, so your linker is trying to find the implementation of it in your Employee class in the .cpp.
Thanks much I'll take a look at that. I appreciate the help, guys. I have to talk to her about this class cause she was great last semester and she sucks now. I get nothing out of her classes, and then she dumps these assignments on us and we don't know how to do it.