我要建立一个Cperson类,是有Cobject,类共有派生的,但是我的MFC里怎么没有Cperson类
解决方案 »
- 为何我的资源视图里面没有icon,menu,string table等编辑器啊?
- 郁闷 今天撞鬼了 DLL共享内存空间问题(有能力的进)在线等待
- 网络编程问题,tcp的,如果客户端掉线(如断开网络,网络质量不好等等),在服务器端是不是能及时捕获这个断开。
- 如何用Socket发送两个回车换行符号,udp协议的。
- 为什么MSDN中没有CMSFlexGrid的信息?从哪里能得到该控件的详细使用说明?
- 怎样在分割窗口的一个视图中获得另一个视图的指针
- 一个类如何从MFC的CList模板类继承??
- 请问哪里有《深入浅出MFC》下栽??
- 明年毕业要到华为上研所工作了 求各位大大给指点迷津
- 邮购。NET的事情
- 消息钩子的问题
- 软件已经完成,想统计用户量,没有服务器?怎么办?
Home | Overview | How Do I | FAQThis article describes the minimum steps necessary to derive a class fromCObject. Other CObject class articles describe the steps needed to take advantage of specific CObject features, such as serialization and diagnostic debugging support.In the discussions of CObject, the terms “interface file” and “implementation file” are used frequently. The interface file (often called the header file, or .H file) contains the class declaration and any other information needed to use the class. The implementation file (or .CPP file) contains the class definition as well as the code that implements the class member functions. For example, for a class named CPerson, you would typically create an interface file named PERSON.H and an implementation file named PERSON.CPP. However, for some small classes that will not be shared among applications, it is sometimes easier to combine the interface and implementation into a single .CPP file.You can choose from four levels of functionality when deriving a class from CObject: Basic functionality: No support for run-time class information or serialization but includes diagnostic memory management.
Basic functionality plus support for run-time class information.
Basic functionality plus support for run-time class information and dynamic creation.
Basic functionality plus support for run-time class information, dynamic creation, and serialization.
Classes designed for reuse (those that will later serve as base classes) should at least include run-time class support and serialization support, if any future serialization need is anticipated.You choose the level of functionality by using specific declaration and implementation macros in the declaration and implementation of the classes you derive from CObject. The following table shows the relationship among the macros used to support serialization and run-time information.Macros Used for Serialization and Run-Time Information
Macro used
CObject::IsKindOf CRuntimeClass::
CreateObject CArchive::operator>>
CArchive::operator<<
Basic CObject functionality No No No
DECLARE_DYNAMIC Yes No No
DECLARE_DYNCREATE Yes Yes No
DECLARE_SERIAL Yes Yes Yes
To use basic CObject functionality Use the normal C++ syntax to derive your class from CObject (or from a class derived from CObject).
The following example shows the simplest case, the derivation of a class from CObject:class CPerson : public CObject
{
// add CPerson-specific members and functions...
}Normally, however, you may want to override some of CObject’s member functions to handle the specifics of your new class. For example, you may usually want to override the Dump function of CObject to provide debugging output for the contents of your class. For details on how to override Dump, see the article Diagnostics: Dumping Object Contents. You may also want to override the AssertValid function of CObject to provide customized testing to validate the consistency of the data members of class objects. For a description of how to override AssertValid, see Overriding the AssertValid Function in the article Diagnostics: Checking Object Validity. The article CObject Class: Specifying Levels of Functionality describes how to specify other levels of functionality, including run-time class information, dynamic object creation, and serialization.