-
Notifications
You must be signed in to change notification settings - Fork 15
/
test2.cpp
92 lines (72 loc) · 1.38 KB
/
test2.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
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
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <map>
#include <set>
#include <memory>
#include <string>
#include "smart_ptr.h"
using namespace smart_ptr;
// X.hpp:
class X
{
public:
virtual void f() = 0;
virtual void g() = 0;
virtual ~X() {
std::cout << "X::~X()" << std::endl;
}
protected:
};
strong_ptr<X> createX();
//-- X.cpp:
class X_impl: public X
{
private:
X_impl(X_impl const &);
X_impl & operator=(X_impl const &);
public:
X_impl()
{
}
virtual ~X_impl()
{
std::cout << "X_impl::~X_impl()" << std::endl;
}
virtual void f()
{
std::cout << "X_impl::f()" << std::endl;
}
virtual void g()
{
std::cout << "X_impl::g()" << std::endl;
}
};
strong_ptr<X> createX()
{
strong_ptr<X> px(new X_impl());
return px;
}
#ifndef CDECL
#if defined(WIN32)
#define CDECL _cdecl
#else
#define CDECL
#endif // defined(WIN32)
#endif // !CDECL
int CDECL main(void)
{
std::string key = "key-string";
strong_ptr<X> sp = createX();
std::map<std::string, strong_ptr<X> > mapSp;
mapSp[key] = sp;
std::map<std::string, strong_ptr<X> >::iterator it;
it = mapSp.find(key);
if (it != mapSp.end()) {
strong_ptr<X> &sp2 = it->second;
if (sp2) {
sp2->f();
}
}
std::set<strong_ptr<X> > setSp;
setSp.insert(sp);
(*setSp.begin())->g();
}