```
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Graphic {
public:
virtual void draw() const = 0;
virtual void add(Graphic *g) {}
};
class Line : public Graphic {
public:
void draw() const {
cout << "Line draw()\n";
}
};
class Rectangle : public Graphic {
public:
void draw() const {
cout << "Rectangle draw() \n";
}
};
// Composite
class Picture : public Graphic {
public:
void draw() const {
for_each(gList.begin(), gList.end(), mem_fn(&Graphic::draw));
}
void add(Graphic *graphic) {
gList.push_back(graphic);
}
private:
vector<Graphic*> gList;
};
int main()
{
Line line;
line.draw();
Rectangle rect;
rect.draw();
Picture pic;
pic.add(&line);
pic.add(&rect);
pic.add(&rect);
pic.draw();
return 0;
}
```