fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <memory>
  4.  
  5. struct foo {
  6. virtual void print() =0;
  7. };
  8.  
  9. struct goo : public foo {
  10. int a;
  11. void print() { std::cout << "goo"; }
  12. };
  13.  
  14. struct moo : public foo {
  15. int a,b;
  16. void print() { std::cout << "moo"; }
  17. };
  18. typedef std::unique_ptr<foo> foo_ptr;
  19. int main() {
  20. std::vector<std::unique_ptr<foo> > foos;
  21. foos.push_back(foo_ptr(new moo));
  22. foos.push_back(foo_ptr(new goo));
  23. foos.push_back(foo_ptr(new goo));
  24. foos.push_back(foo_ptr(new moo));
  25.  
  26. for(auto it = foos.begin(); it!=foos.end(); ++it) {
  27. it->get()->print();
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
moogoogoomoo