-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComposite.cpp
More file actions
80 lines (58 loc) · 1.23 KB
/
Composite.cpp
File metadata and controls
80 lines (58 loc) · 1.23 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Composite.hpp
// COns
//
// Created by zhTian on 16/4/16.
// Copyright © 2016年 zhTian. All rights reserved.
//
#ifndef Composite_hpp
#define Composite_hpp
#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>
class Graghic
{
public:
Graghic(){}
Graghic(const Graghic&){}
Graghic& operator=(const Graghic&) = delete;
virtual ~Graghic(){}
public:
virtual void print() const = 0;
};
class Ellipse : public Graghic
{
public:
Ellipse(){}
Ellipse(const Ellipse&){}
Ellipse& operator=(const Ellipse&) = delete;
virtual ~Ellipse(){}
public:
void print() const
{
std::cout << "Ellipse." << std::endl;
}
};
class CompositeGraghic : public Graghic
{
public:
CompositeGraghic(){}
CompositeGraghic(const CompositeGraghic&){}
CompositeGraghic& operator=(const CompositeGraghic&) = delete;
virtual ~CompositeGraghic(){}
public:
void print() const
{
for_each(m_graphicList.begin(), m_graphicList.end(), [](Graghic *a){
a->print();
});
}
void add(Graghic *g)
{
m_graphicList.push_back(g);
}
private:
std::vector<Graghic*> m_graphicList;
};
#endif /* Composite_hpp */