fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. public:
  7. void print() const { cout << "A" << endl; }
  8. };
  9.  
  10. class B : public A
  11. {
  12. public:
  13. void print() const { cout << "B" << endl; }
  14. };
  15.  
  16. class C
  17. {
  18. public:
  19. virtual void print() const { cout << "C" << endl; }
  20. };
  21.  
  22. class D : public C
  23. {
  24. public:
  25. void print() const { cout << "D" << endl; }
  26. };
  27.  
  28.  
  29. int main() {
  30. A* a = new B;
  31. a->print();
  32.  
  33. C* c = new D;
  34. c->print();
  35. // your code goes here
  36. return 0;
  37. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
A
D