language: C++ 4.7.2 (gcc-4.7.2)
date: 436 days 11 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <boost/ptr_container/ptr_vector.hpp>
#include <vector>
 
class Animal
{
public:
    virtual Animal* clone() const = 0;
    virtual char type() = 0;
};
 
Animal* new_clone(Animal const& other){
  return other.clone();
}
 
class Cat : public Animal
{
public:
    Cat* clone() const{ return new Cat(*this); }
    char type() { return 1; }
};
 
class Zoo
{
public:
    boost::ptr_vector<Animal> animals;
};
 
int main()
{
    std::vector<Zoo> allZoos;
 
    Zoo ourCityZoo;
    ourCityZoo.animals.push_back(new Cat());
 
    allZoos.push_back(ourCityZoo);
    allZoos.clear();
 
    return 0;
}