fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. virtual void print() { cout << "A::print" << endl; }
  9. };
  10.  
  11. class B : public A
  12. {
  13. public:
  14. virtual void print() { cout << "B::print" << endl; }
  15. };
  16.  
  17. int main()
  18. {
  19. A** array = new A*[2];
  20. array[0] = new A();
  21. array[1] = new B();
  22. for (int i = 0; i < 2; i++)
  23. array[i]->print();
  24. return 0;
  25. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
A::print
B::print