fork(4) download
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. public:
  6. virtual void whoAmI()
  7. {
  8. std::cout << "\nI'm base\n" ;
  9. }
  10. };
  11.  
  12. class Derived : public Base
  13. {
  14. };
  15.  
  16.  
  17. class SecondDerivative : public Derived
  18. {
  19. public:
  20. virtual void whoAmI()
  21. {
  22. std::cout << "\nI'm Second derivative\n" ;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. SecondDerivative SD;
  29. Base* b = &SD;
  30. b->whoAmI();
  31.  
  32. Derived d;
  33. b = &d;
  34. b->whoAmI();
  35. return 0;
  36. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
I'm Second derivative

I'm base