MSDN中解释说:
Use the DECLARE_DYNCREATE macro to enable objects of CObject-derived classes to be created dynamically at run time
我想new也是动态创建对象呀,哪位大侠可以很清楚的讲解一下个中奥妙?

解决方案 »

  1.   

    也可以通过该类的CRuntimeClass来创建
      

  2.   

    如何通过名字("字符串")来创建,这个字符串可以是变量吗?
    比如:CString className = "CClassName";
    可以通过className这个变量来创建对象吗?
      

  3.   

    There are 3 member functions and 1 data member defined in this Macro definition:
    1. _GetBaseClass(); 
    2. GetRuntimeClass();
    3. CreateObject();
    4. An static data member of type CRuntimeClass, which contains all userful information related to the defintion of this class, such as class name, base class, the function to be used to create an object of this class, and so on. Among the 4 members, 1, 2, 4 are static member, while 2 is virtual function which finally access the static data member. Obviously, this Macro defines the base of a class (class related infomation). As what you know, code in C++ is finally translated into C code by preprocessor. There must be some place where those information for the definition of particular class stays. This macro, together with macro IMPLEMENT_DYNCREATE, define and implement this part of functionality.