我的文档类里有个list<CBaseClass*> m_mPBaseList; 
CBaseClass是个基类,它有一些派生类。 
但都实现了serialize()
存档时,我循环list,调用每个对像的serialize, 
读档时怎么实现?
关健是有一些是从CBaseClass 派生的,但不能肯定是哪个类,怎么创造这些派生类?然后调用serialize().

解决方案 »

  1.   

    Derive your class from CObject and implement serialization
    use pMyObject->IsKindOf( RUNTIME_CLASS( CMyClass ) ) to check the object is an instance of a derived class.Hope this may work
      

  2.   

    // Derive your class from CObject and implement serialization
    Derive your class from CObject and implement dynamic creation
      

  3.   

    将每一个子类的序列化函数做好。因为序列化函数是虚函数。所以会自动用对应的子类做序列化工作。你可以在基类中定义一个enum变量来标记当前是那个子类。