封装数据库类模拟 auto_ptr

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
class CRecordsetObject
{
public:
CRecordset* __init;
public:
inline CRecordset* operator->()
{
return __init;
}
CRecordsetObject(CDatabase* pDatabase);
~CRecordsetObject(void);

private:
CRecordsetObject operator=(const CRecordsetObject&);
CRecordsetObject (const CRecordsetObject&);
CRecordsetObject ();
};

CRecordsetObject::CRecordsetObject(CDatabase* pDatabase)
:__init(NULL)
{
__init = new CRecordset(pDatabase);
}

CRecordsetObject::~CRecordsetObject(void)
{
if (NULL != __init)
{
delete __init;
__init = NULL;
}
}
1
2
3
CRecordsetObject Object(pDatabase);
Object->m_strFilter.Format("");
// 不用关心内存的释放了