Skip to content

Commit

Permalink
Разрешаване на проблема с диаманта за print
Browse files Browse the repository at this point in the history
  • Loading branch information
triffon committed May 8, 2019
1 parent a1b4a54 commit bb867c6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion highorder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ void testderive() {
int main() {
// testtypes();
testaccumulate();
// testderive();
testderive();
return 0;
}
11 changes: 8 additions & 3 deletions player/boss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ Boss::Boss(char const* n, int s,
Player(n, s), Hero(n, s, lvl), Bot(n, s, algo, t, d), damage(dmg) {}

void Boss::print(std::ostream& os) const {
Hero::print(os);
Bot::print(os);
os << " и нанася поражения " << getDamage();
Player::print(os);
printDirect(os);
}

void Boss::printDirect(std::ostream& os) const {
os << ", който е boss";
Hero::printDirect(os);
Bot::printDirect(os);
os << " и нанася поражения " << getDamage();
}
3 changes: 3 additions & 0 deletions player/boss.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Boss : public Bot, public Hero {
unsigned getDamage() const { return damage; }

void print(std::ostream& os = std::cout) const;

protected:
void printDirect(std::ostream& os = std::cout) const;
};

#endif
13 changes: 9 additions & 4 deletions player/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ Bot::Bot(char const* n, int s,
difficulty(d)
{}

void Bot::print(std::ostream& os) const {
Player::print();
void Bot::printDirect(std::ostream& os) const {
os << " и е бот с ниво на трудност "
<< getDifficulty()
<< ", реализиран от";
AI::print();
<< ", реализиран от ";
AI::print(os);
}


void Bot::print(std::ostream& os) const {
Player::print(os);
printDirect(os);
}

std::ostream& operator<<(std::ostream& os, Bot const& b) {
Expand Down
4 changes: 4 additions & 0 deletions player/bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Bot : virtual public Player, public AI {

void print(std::ostream& os = std::cout) const;

protected:

void printDirect(std::ostream& os = std::cout) const;

};

std::ostream& operator<<(std::ostream& os, Bot const& b);
Expand Down
8 changes: 6 additions & 2 deletions player/hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Hero::Hero(char const* n, int s,
unsigned lvl) : level(lvl), Player(n, s) {
}

void Hero::print(std::ostream& os) const {
Player::print();
void Hero::printDirect(std::ostream& os) const {
os << " и е герой на ниво " << getLevel();
}

void Hero::print(std::ostream& os) const {
Player::print(os);
printDirect(os);
}
3 changes: 3 additions & 0 deletions player/hero.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Hero : virtual public Player {
virtual unsigned getLevel() const { return level; }

void print(std::ostream& os = std::cout) const;

protected:
void printDirect(std::ostream& os = std::cout) const;
};

#endif
8 changes: 7 additions & 1 deletion player/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ void testBinding() {
void testBoss() {
Boss boss("Саурон", 50, "Тъмни сили", 2.8,
100, 20, 1000);
boss.print();
std::cout << boss;
std::cout << ((Hero&)boss).getName() << std::endl;
std::cout << ((Bot&)boss).getName() << std::endl;
Bot b("HAL 9000", 100, "α-β", 0.7, 9000);
std::cout << b;
Hero h("Гандалф Сивия", 45, 10);
std::cout << h;
Player* p = &h;
p->print();
}

int main() {
Expand Down

0 comments on commit bb867c6

Please sign in to comment.