I am having trouble with adding an object to a set.
I use two classes in a header file, one for employees and a second one for managers. In the manager class I want to create a set of employees by adding employees who are subordinates for a particular manager. First I create a empty set for which I can add objects by calling a function.
It looks as follows:
header file
#ifndef EMPLOYEE_HH
#define EMPLOYEE_HH
#include <set>
#include <string>
#include <iostream>
using namespace std ;
class Employee {
public:
// Constructor
Employee(const char* name, double salary) :
_name(name),
_salary(salary) {
}
// Accessors
const char* name() const {
return _name.c_str() ;
}
double salary() const {
return _salary ;
}
private:
string _name ;
double _salary ;
} ;
class Manager : public Employee {
public:
//Constructor
Manager(const char* _name, double _salary):
Employee(_name, _salary),
_subordinates() {
}
// Accessors/Modifiers
void addSubordinate(Employee& empl) {
_subordinates.insert(empl) ; // Error: no macthing function call for .insert()
}
private:
set<Employee*> _subordinates ;
} ;
#endif
Main script
#include <string>
#include <iostream>
#include "Employee.hh"
using namespace std ;
int main() {
Employee emp = ("David", 10000) ;
Manager mgr = ("Oscar", 20000) ;
mgr.addSubordinate(emp);
return 0;
}
When compiling I get the error that no matching function can be called for _subordinates.insert(empl)
.