I
I
Ivan Erokhin2016-10-12 15:06:00
OOP
Ivan Erokhin, 2016-10-12 15:06:00

C++ operator overloading?

Hello. I'm trying to figure out oops. We asked such a lab:
1. Determine the class according to the task variant (Table 1, column 2).
2. Define and implement constructors, destructor, Input (keyboard input) and Print (screen output) functions in the class, overload the assignment operation.
3. Supplement the definition of the class with the given overloaded operations (according to the variant, Table 1., Column 2.3).
4. Realize those deals. Run testing.
It seems like everything is clear, but the following values ​​are given:
9. Worker: last name, salary, year of employment
Operation1: Determine how many workers with the same name
Operation2: Reduce the salary of an employee
How can I overload operation 1:? I can't understand this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2016-10-12
@Free_ze

It seems to me that the assignment meant an overload of equality ("=="), i.e. we can go through the collection of workers and compare it with a certain standard

class Worker {
    std::string _name;
    ...
public:
    bool operator==(const Worker& other) const {
         return _name == other.name;
    }
};

//....

std::vector<Worker> workers = {...};
int count = std::count(begin(workers), end(workers), Worker("Vasili Pupkin"));

J
Junior007, 2016-10-12
@Junior007

https://www.youtube.com/watch?v=Qn6mu9l6Xj8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question