原型:virtual void Dump( CDumpContext& dc ) const;
用途:将对象的内容转储到CDumpContext 对象中,用于诊断输出,用于转储的诊断性转储文本,通常为afxDump;
示例:
// example for CObject::Dump
#ifdef _DEBUG
void CAge::Dump( CDumpContext &dc ) const
{
CObject::Dump( dc );
dc << "Age = " << m_years;
}
#define _DEBUG
注意:Dump()调用仅仅在Microsoft基础类库的调试版本中有意义。编写了自己的类后,应当覆盖Dump函数,来为你自己和使用你的类的用户提供诊断服务。被覆盖的Dump在打印对应于派生类的数据成员之前,通常调用它基类的Dump函数。Dump是一个常量函数,那么在转储期间不允许改变对象的状态。Dump 函数将对象的成员变量的文本化表示形式写入转储上下文 (CDumpContext)。转储上下文类似于 I/O 流。可以使用插入运算符 (<<)向 CDumpContext 发送数据。