fork download
  1. class Animal // base class
  2. {
  3. int weight;
  4. public:
  5. int getWeight() { return weight;};
  6. };
  7. class Tiger : public Animal { /* ... */ };
  8. class Lion : public Animal { /* ... */ };
  9. class Liger : public Tiger, public Lion { /* ... */ };
  10. int main()
  11. {
  12. Liger lg ;
  13. /*COMPILE ERROR, the code below will not get past
  14.   any C++ compiler */
  15. int weight = lg.getWeight();
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15:22: error: request for member ‘getWeight’ is ambiguous
prog.cpp:5:10: error: candidates are: int Animal::getWeight()
prog.cpp:5:10: error:                 int Animal::getWeight()
prog.cpp:15:10: warning: unused variable ‘weight’ [-Wunused-variable]
stdout
Standard output is empty