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