fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <memory>
  4. using namespace std;
  5.  
  6. class SandboxObject {
  7. public:
  8. virtual void show() const { cout << "Unknown sandbox object " << this <<endl; }
  9. };
  10. class Circle : public SandboxObject {
  11. public:
  12. void show() const override { cout << "Circle " << this <<endl; }
  13. };
  14. class Rectangle : public SandboxObject {
  15. public:
  16. void show() const override { cout << "Rectangle " << this <<endl; }
  17. };
  18.  
  19. int main() {
  20. vector<shared_ptr<SandboxObject>> universe;
  21. universe.push_back(make_shared<Circle>());
  22. universe.push_back(make_shared<Rectangle>());
  23. universe.push_back(make_shared<Circle>());
  24. for (auto x:universe)
  25. x->show();
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 5684KB
stdin
Standard input is empty
stdout
Circle 0x55f46cddbe80
Rectangle 0x55f46cddbec0
Circle 0x55f46cddbea0