more effective c++对象产生于head(23)

作者安排了一个基类和派生类的调用方式

1、基类先封装 destroy函数提供外部调用

void destroy() const {delete this;}

2、基类析构函数他说要限制为protected,我不懂。
我想应该是让外部调用必须使用destroy来销毁对象吧!

来看下调用和派生++
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
class UPNumber
{
public:
UPNumber(arguments);
protected:
~UPNumber();
/* data */
};
class Asset
{
public:
Asset(arguments);
~Asset();
private:
UPNumber* value;
/* data */
};
Asset::Asset(arguments)
: value(new UPNumber(arguments)) {
...
}
Asset::~Asset()
{
value->destroy();
}

派生类产生基类数据于头,设置基类数据对象来调用函数。
析构使用基类自释放性!

// //