fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct Shape {};
  5.  
  6. struct Circle : public Shape
  7. {
  8. Circle()
  9. {
  10. std::cout << __PRETTY_FUNCTION__ << '\n';
  11. }
  12. };
  13.  
  14. struct Rectangle : public Shape
  15. {
  16. Rectangle()
  17. {
  18. std::cout << __PRETTY_FUNCTION__ << '\n';
  19. }
  20. };
  21.  
  22. int main()
  23. {
  24. for (int i=0; i<5; ++i)
  25. {
  26. std::unique_ptr<Shape> sp = (i % 2)
  27. ? std::unique_ptr<Shape>(new Circle())
  28. : std::unique_ptr<Shape>(new Rectangle());
  29. }
  30.  
  31. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Rectangle::Rectangle()
Circle::Circle()
Rectangle::Rectangle()
Circle::Circle()
Rectangle::Rectangle()