I'm working with a std::set<Employee*, Employee::EmployeeComparator >.
First here is the Class Manager:
class Manager : public Employee
{
public:
//C'tors & d'tor//
Manager(int id, std::string first_name, std::string last_name, int year);
Manager(const Manager& other) = default;
~Manager() = default;
//Methods//
[...]
private:
std::set<Employee*, Employee::EmployeeComparator > m_employees;
};
class EmployeeComparator {
public:
bool operator()(const Employee* emp1, const Employee* emp2) const {
return emp1->getId() < emp2->getId();
}
};
Now, I'm trying to iterate over m_employee and erase all of them from the set:
void Manager::fireEmployees(int salary_to_reduce) {
for (auto it = m_employees.begin(); it != m_employees.end(); ++it) {
(*it)->setSalary(-salary_to_reduce);
m_employees.erase(*it);
}
}
the m_employees.erase failed:
Unhandled exception at 0x00007FFBDD097FBC (ucrtbased.dll) in Citizens Management System (C++ training).exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
*The error also opens a file called 'xtree,' which I assume is part of the set implementation.
is the class Manager should meet special requirements that I'm not aware of?
is the functor written correctly?
Any guidance on how to solve this would be greatly appreciated.