-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPimplMode.cpp
69 lines (48 loc) · 1.16 KB
/
PimplMode.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
#include "PimplMode.h"
//方式1:
//类中包含类型为 Impl 的指针成员变量
class CSocketClient::Impl
{
public:
//一些方法,可供用指针调用
public:
short m_nPort;
char m_szServer[64];
long m_nLastDataTime; //最近一次收发数据的时间
long m_nHeartbeatInterval; //心跳包时间间隔,单位秒
};
CSocketClient::CSocketClient()
{
m_pImpl = new Impl();
}
CSocketClient::~CSocketClient()
{
delete m_pImpl;
}
short CSocketClient::getPort()
{
return m_pImpl->m_nPort;
}
//方式2:
//类中包含类型为 Impl 的智能指针成员变量
class CSocketClientV2::Impl
{
public:
//一些方法,可供用指针调用
public:
short m_nPort;
char m_szServer[64];
long m_nLastDataTime; //最近一次收发数据的时间
long m_nHeartbeatInterval; //心跳包时间间隔,单位秒
};
CSocketClientV2::CSocketClientV2()
:m_pImpl(std::make_unique<Impl>())
{
}
CSocketClientV2::~CSocketClientV2()
{
}
short CSocketClientV2::getPort()
{
return m_pImpl->m_nPort;
}