fork(10) download
  1. #include <iostream>
  2. #include <vector>
  3. struct Base {
  4. virtual void f() { std::cout << "Base\n"; }
  5. virtual ~Base(){}
  6. };
  7. struct Derived : Base {
  8. void f() { std::cout << "Derived\n"; }
  9. };
  10. int main()
  11. {
  12. std::vector<Base> v;
  13. v.push_back(Derived()); // bad idea
  14. v[0].f();
  15. }
  16.  
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
Base