fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. public:
  7. virtual void doSomething()
  8. {
  9. std::cout<<"\nIn A::doSomething()";
  10. }
  11. };
  12.  
  13. class B : public A
  14. {
  15. public:
  16. virtual void doSomething()
  17. {
  18. std::cout<<"\nIn B::doSomething()";
  19. }
  20. };
  21.  
  22.  
  23.  
  24. int main()
  25. {
  26. B b;
  27. A obj;
  28. A* a = &b;
  29. a->doSomething();
  30.  
  31. a = &obj;
  32. a->doSomething();
  33.  
  34. return 0;
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
In B::doSomething()
In A::doSomething()