fork download
  1. #include <boost/ptr_container/ptr_vector.hpp>
  2. #include <vector>
  3.  
  4. class Animal
  5. {
  6. public:
  7. virtual Animal* clone() const = 0;
  8. virtual char type() = 0;
  9. };
  10.  
  11. Animal* new_clone(Animal const& other){
  12. return other.clone();
  13. }
  14.  
  15. class Cat : public Animal
  16. {
  17. public:
  18. Cat* clone() const{ return new Cat(*this); }
  19. char type() { return 1; }
  20. };
  21.  
  22. class Zoo
  23. {
  24. public:
  25. boost::ptr_vector<Animal> animals;
  26. };
  27.  
  28. int main()
  29. {
  30. std::vector<Zoo> allZoos;
  31.  
  32. Zoo ourCityZoo;
  33. ourCityZoo.animals.push_back(new Cat());
  34.  
  35. allZoos.push_back(ourCityZoo);
  36. allZoos.clear();
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout

Standard output is empty