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