fork download
  1. #include <iostream>
  2.  
  3. class Base {
  4. public:
  5. virtual int myFunc1 () = 0;
  6. virtual int myFunc2 () = 0;
  7. };
  8.  
  9. class Derived1 : public Base {
  10. public:
  11. int myFunc1 () { return 1; }
  12. int myFunc2 () { return 2; }
  13. };
  14.  
  15. class Derived2 : public Base {
  16. public:
  17. int myFunc1 () { return 3; }
  18. int myFunc2 () { return 4; }
  19. };
  20.  
  21. void someFunction (Base* base) {
  22. int x = base->myFunc1 ();
  23. int y = base->myFunc2 ();
  24. std::cout << (x * y) << std::endl;
  25. }
  26.  
  27. int main () {
  28. Derived1 d1;
  29. Derived2 d2;
  30.  
  31. someFunction (&d1);
  32. someFunction (&d2);
  33. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
2
12