fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Figure {
  6. public:
  7. virtual void print() const = 0;
  8. };
  9.  
  10. class Circle : public Figure {
  11. public:
  12. void print() const override {
  13. cout << "Circle" << endl;
  14. }
  15. };
  16.  
  17. class Triangle : public Figure {
  18. public:
  19. void print() const override {
  20. cout << "Triangle" << endl;
  21. }
  22. };
  23.  
  24. void log(const Figure &figure) {
  25. figure.print();
  26. }
  27.  
  28. int main() {
  29. vector<Figure*> figures;
  30. figures.push_back(new Circle());
  31. figures.push_back(new Triangle());
  32.  
  33. for(auto &figure : figures) {
  34. figure->print();
  35. }
  36.  
  37. for(auto &figure : figures) {
  38. delete figure;
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
Circle
Triangle