1 | % xlC -qversion
|
---|
2 | C for AIX version 6.0.0.0radhas@peibm116:/remote/us01home5/radhas/test_prog% cat boost_ptr_vec.cpp
|
---|
3 | #include <boost/ptr_container/ptr_vector.hpp>
|
---|
4 | #include <string>
|
---|
5 | #include <iostream>
|
---|
6 | using namespace std;
|
---|
7 | class animal : boost::noncopyable
|
---|
8 | {
|
---|
9 | public:
|
---|
10 | virtual ~animal() {}
|
---|
11 | virtual void eat() = 0;
|
---|
12 | virtual int age() const = 0;
|
---|
13 | // ...
|
---|
14 | };
|
---|
15 | class mammal:public animal
|
---|
16 | {
|
---|
17 | public:
|
---|
18 | string name;
|
---|
19 | mammal(string set_name)
|
---|
20 | {
|
---|
21 | name=set_name;
|
---|
22 | }
|
---|
23 | void eat()
|
---|
24 | {
|
---|
25 | }
|
---|
26 | int age() const
|
---|
27 | {
|
---|
28 | return 1;
|
---|
29 | }
|
---|
30 | };
|
---|
31 | class bird:public animal
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | string name;
|
---|
35 | bird(string set_name)
|
---|
36 | {
|
---|
37 | name=set_name;
|
---|
38 | }
|
---|
39 | void eat()
|
---|
40 | {
|
---|
41 | }
|
---|
42 | int age() const
|
---|
43 | {
|
---|
44 | return 1;
|
---|
45 | }
|
---|
46 | };
|
---|
47 |
|
---|
48 | class zoo
|
---|
49 | {
|
---|
50 | boost::ptr_vector<animal> the_animals;
|
---|
51 | public:
|
---|
52 |
|
---|
53 | void add_animal( animal* a )
|
---|
54 | {
|
---|
55 | the_animals.push_back( a );
|
---|
56 | }
|
---|
57 | };
|
---|
58 |
|
---|
59 | int main()
|
---|
60 | {
|
---|
61 | zoo the_zoo;
|
---|
62 | the_zoo.add_animal( new mammal("joe") );
|
---|
63 | the_zoo.add_animal( new bird("dodo") );
|
---|
64 |
|
---|
65 | }
|
---|