blob: 4a0b37824a3309790b9444263391037646b3d6c6 (
plain)
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
|
#include "player.hh"
Player::Player(const std::string& name, int age, int guess)
: name_(name)
, age_(age)
, guess_(guess)
{
if (name.empty())
throw InvalidArgumentException{ "Name can't be empty." };
if (age < 0)
throw InvalidArgumentException{
"Well, it seems you are not born yet."
};
if (age > 150)
throw InvalidArgumentException{ "Sorry gramp, too old to play." };
}
int Player::get_guess() const
{
return guess_;
}
bool Player::operator==(const Player& p) const
{
return this == &p;
}
bool Player::operator!=(const Player& p) const
{
return this != &p;
}
std::ostream& operator<<(std::ostream& os, const Player& p)
{
return os << p.name_ << '(' << p.age_ << ')';
}
|