-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun_with_operators.cpp
More file actions
45 lines (36 loc) · 1.01 KB
/
fun_with_operators.cpp
File metadata and controls
45 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
7 kyu
Fun with operators
https://www.codewars.com/kata/5813084c6858b6ba7b00006a
*/
class Person {
public:
Person(int age);
bool operator==(const Person& other) const;
bool operator!=(const Person& other) const;
bool operator<=(const Person& other) const;
bool operator>=(const Person& other) const;
bool operator<(const Person& other) const;
bool operator>(const Person& other) const;
private:
const int m_age;
};
Person::Person(int age) : m_age(age) {}
bool Person::operator==(const Person& other) const {
return m_age == other.m_age;
}
bool Person::operator!=(const Person& other) const {
return !operator==(other);
}
bool Person::operator<=(const Person& other) const {
return m_age <= other.m_age;
}
bool Person::operator>=(const Person& other) const {
return m_age >= other.m_age;
}
bool Person::operator<(const Person& other) const {
return operator<=(other) && operator!=(other);
}
bool Person::operator>(const Person& other) const {
return operator>=(other) && operator!=(other);
}