fork download
  1. #include <iostream>
  2. using namespace std;
  3. class B
  4. {
  5. public:
  6. virtual void display()
  7. { cout<<"Content of base class.\n"; }
  8. };
  9.  
  10. class D : public B
  11. {
  12. public:
  13. void display()
  14. { cout<<"Content of derived class.\n"; }
  15. };
  16.  
  17. int main()
  18. {
  19. B *b;
  20. D d;
  21.  
  22.  
  23. b = &d; /* Address of object d in pointer variable */
  24. b->display();
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Content of derived class.