fork(6) download
  1.  
  2. #include <iostream>
  3. #include <memory>
  4. #include <vector>
  5.  
  6. class Foo
  7. {
  8. public:
  9. virtual void fooFunc()
  10. {
  11. std::cout << "Foo\n";
  12. }
  13. };
  14.  
  15. class Bar : public Foo
  16. {
  17. public:
  18. virtual void fooFunc()
  19. {
  20. std::cout << "Bar\n";
  21. }
  22. };
  23.  
  24. int main()
  25. {
  26. std::vector< std::shared_ptr<Foo> > vec;
  27. vec.push_back(std::static_pointer_cast<Foo>(std::make_shared<Bar>()));
  28. vec.back()->fooFunc();
  29. vec.push_back(std::make_shared<Bar>());
  30. vec.back()->fooFunc();
  31. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Bar
Bar