乱记Serializable Class

通俗的说,一个可以Serializable的类就是支持archive<<和archive>>操作的类。如何定义一个Serializable Class

Five main steps are required to make a class serializable. They are listed below and explained in the following sections:

  1. Deriving your class from CObject (or from some class derived from CObject).

  2. Overriding the Serialize member function.  例如ar<<CGraph;实际上是调用friend CArchive& operator <<( CArchive& ar, const CObject* pOb ); (所以这里就要求Serializable Class类CGraph从CObject继承),然后应该是这个友员函数内部通过pOb调用了CGraph的Serialize成员函数。

  3. Using the DECLARE_SERIAL macro in the class declaration. 

  4. Defining a constructor that takes no arguments.

  5. Using the IMPLEMENT_SERIAL macro in the implementation file for your class.

If you call Serialize directly rather than through the >> and << operators of CArchive, the last three steps are not required for serialization.

注意:用在类doc中增加虚函数 CDocument::DeleteContents ,该函数在文档新建、打开或者关闭的时候调用,来释放堆内存空间。经过测试发现该函数是在view类对象析构之后调用,所以要求把要释放的内存的相关数据放在doc类对象中。
Called by the framework to delete the document’s data without destroying the CDocument object itself. It is called just before the document is to be destroyed. It is also called to ensure that a document is empty before it is reused. This is particularly important for an SDI application, which uses only one document; the document is reused whenever the user creates or opens another document. Call this function to implement an “Edit Clear All” or similar command that deletes all of the document’s data. The default implementation of this function does nothing. Override this function to delete the data in your document.
待续中……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值