看了相关资料,还有有点不明白
对于类的串行化问题. 摘自网络的程序如下
  CYourClass   :   public   CObject  
  {  
         DECLARE_SERIAL(CYourClass)   //很重要一定要加上  
  public:  
         virtual   void   Serialize(CArchive&   ar);  
  public:  
        int   m_iVal;  
        float   m_fVal;  
  };  
在实现文件中:  
  IMPLEMENT_SERIAL(CYourClass   ,   CObject   ,   1)    
  void   CYourClass::Serialize(CArchive&   ar)  
  {  
      if(ar.IsLoading())  
      {  
          //从文件中读取数据到内存中,比如  
          ar   >>   m_iVal;  
          ar   >>   m_fVal;  
      }  
      else   if(ar.IsStoring())  
      {  
          ar   <<   m_iVal;  
          ar   <<   m_fVal;  
      }    
  }我的问题.上面的代码中,DECLARE_SERIAL(CYourClass) 与 IMPLEMENT_SERIAL(CYourClass   ,   CObject   ,   1)    
这两句必须都要出现吗? 如果 IMPLEMENT_SERIAL(CYourClass   ,   CObject   ,   1)   不要呢,程序还能正常吗?

解决方案 »

  1.   

    Use the IMPLEMENT_SERIAL macro in a .cpp module; then link the resulting object code only once.You can use the AFX_API macro to automatically export the CArchive extraction operator for classes that use the DECLARE_SERIAL and IMPLEMENT_SERIAL macros. Bracket the class declarations (located in the .h file) with the following code:Visual C++  Copy Code 
    #undef AFX_API
    #define AFX_API AFX_EXT_CLASS// <your class declarations here>#undef AFX_API
    #define AFX_API
     For more information, see the CObject Class Topics.相信你能看懂
      

  2.   

    msdn 上有很详细的文档说明
    使用 MFC的序列化 须满足下面几个条件
    1 类 必须派生自 CObject
    2 类 声明中 添加 DECLARE_SERIAL 宏
      类 实现中 添加 IMPLEMENT_SERIAL 宏
    3 类 必须提供一个 无参数的构造函数
    4 重写 你自己的 Serialize()函数