fork download
  1. #include <iostream>
  2.  
  3. class IPlayer
  4. {
  5. public:
  6. virtual bool IsValid() = 0;
  7. virtual bool Equals(const IPlayer *other) = 0;
  8. };
  9.  
  10. class ILocalPlayer : virtual public IPlayer
  11. {
  12. public:
  13. virtual bool CanShoot() = 0;
  14. };
  15.  
  16. class SourcePlayer : virtual public IPlayer
  17. {
  18. public:
  19. SourcePlayer(int index)
  20. : index(index)
  21. {
  22.  
  23. }
  24.  
  25. virtual bool IsValid()
  26. {
  27. return true;
  28. }
  29.  
  30. virtual bool Equals(const IPlayer *other)
  31. {
  32. //const SourcePlayer *p = dynamic_cast<const SourcePlayer*>(other);
  33. //return index == p->index;
  34. return Equals(dynamic_cast<const SourcePlayer*>(other));
  35. }
  36.  
  37. bool Equals(const SourcePlayer *other)
  38. {
  39. return index == other->index;
  40. }
  41.  
  42. private:
  43. int index;
  44. };
  45.  
  46. class SourceLocalPlayer : public SourcePlayer, public ILocalPlayer
  47. {
  48. public:
  49. SourceLocalPlayer(int index)
  50. : SourcePlayer(index)
  51. {
  52.  
  53. }
  54.  
  55. virtual bool CanShoot()
  56. {
  57. return false;
  58. }
  59. };
  60.  
  61. int main()
  62. {
  63. ILocalPlayer *local = new SourceLocalPlayer(1);
  64. IPlayer *player = new SourcePlayer(1);
  65.  
  66. std::cout << (local->Equals(player) ? "gleich" : "ungleich");
  67.  
  68. delete player;
  69. delete local;
  70. }
Runtime error #stdin #stdout 0s 3984KB
stdin
Standard input is empty
stdout
gleich