fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. public:
  7. virtual void func()
  8. {
  9. std::cout<<"in A's func "<<std::endl;
  10. }
  11. };
  12.  
  13. class B : public A
  14. {
  15.  
  16. };
  17.  
  18. class C : public B
  19. {
  20.  
  21. public:
  22. void func()
  23. {
  24. std::cout<<"in C's func "<<std::endl;
  25. }
  26. };
  27.  
  28. int main() {
  29. // your code goes here
  30. A* obj = new A();
  31. obj->func();
  32.  
  33. A* obj2 = new B();
  34. obj2->func();
  35.  
  36. A* obj3 = new C();
  37. obj3->func();
  38.  
  39. B* obj5 = new B();
  40. obj5->func();
  41.  
  42. B* obj6 = new C();
  43. obj6->func();
  44.  
  45. C* obj7 = new C();
  46. obj7->func();
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
in A's func 
in A's func 
in C's func 
in A's func 
in C's func 
in C's func