fork download
  1. #include <iostream>
  2.  
  3. enum classId
  4. {
  5. person,
  6. gunslinger,
  7. pokerplayer,
  8. baddude,
  9. };
  10.  
  11. class Person
  12. {
  13. public:
  14. int foo;
  15.  
  16. Person( ) : foo( classId::person ) { }
  17. Person( int f ) : foo( f ) { }
  18.  
  19. Person( const Person &) = default;
  20.  
  21. int get_foo( ) const
  22. {
  23. return foo;
  24. }
  25. };
  26.  
  27. class Gunslinger : public Person
  28. {
  29. public:
  30. Gunslinger( ) : Person( classId::gunslinger ) { }
  31. Gunslinger( int f ) : Person( f ) { }
  32.  
  33. Gunslinger( const Gunslinger &) = default;
  34. };
  35.  
  36. class PokerPlayer : virtual public Person
  37. {
  38. public:
  39. PokerPlayer( ) : Person( classId::pokerplayer ) { }
  40. PokerPlayer( int f ) : Person( f ) { }
  41.  
  42. PokerPlayer( const PokerPlayer &) = default;
  43. };
  44.  
  45. class BadDude : public Gunslinger, public PokerPlayer
  46. {
  47. public:
  48. BadDude( ) : Gunslinger::Person( classId::baddude ), Gunslinger(classId::baddude), PokerPlayer( classId::baddude ) { }
  49. };
  50.  
  51.  
  52. int main( )
  53. {
  54. BadDude bd;
  55.  
  56. std::cout << static_cast<Gunslinger>(bd).get_foo() << std::endl;
  57. std::cout << static_cast<PokerPlayer>(bd).get_foo() << std::endl;
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
3
3