-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathproxy.cpp
49 lines (46 loc) · 1023 Bytes
/
proxy.cpp
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
#include<iostream>
#include<string>
using namespace std;
class RealImage {
int m_id;
public:
RealImage(int i) {
m_id = i;
cout << " $$ ctor: " << m_id << '\n';
}
~RealImage() {
cout << " dtor: " << m_id << '\n';
}
void draw() {
cout << " drawing image " << m_id << '\n';
}
};
class Image {
RealImage *m_the_real_thing;
int m_id;
static int s_next;
public:
Image() {
m_id = s_next++;
m_the_real_thing = 0;
}
~Image() {
delete m_the_real_thing;
}
void draw() {
if (!m_the_real_thing)
m_the_real_thing = new RealImage(m_id);
m_the_real_thing->draw();
}
};
int Image::s_next = 1;
int main() {
Image images[5];
for (int i; true;) {
cout << "Exit[0], Image[1-5]: ";
cin >> i;
if (i == 0)
break;
images[i - 1].draw();
}
}