2011-11-06 107 views
1

我創建了我的類CData並從CObject派生它,因爲我需要序列化它。從CObject導出序列化導致訪問編譯器錯誤

class CData : public CObject 
{ 
    DECLARE_SERIAL(CData); 
public: 
    CData(); 
    virtual ~CData(); 
    virtual void Serialize(CArchive& ar); 

    //Data 
    CString m_strName; 
    ULONG m_ulID; 
    CString m_strCorps; 
    CPoint m_Coordinate; 
    short m_sStatus; 
}; 

而我在我的文檔類中使用類型爲vector<CData>的矢量。我在程序運行期間使用vecData.push_back(Data)(其中Data是CData類型)向矢量添加新的CData對象。

但是當我嘗試編譯此我得到以下錯誤:

error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'

我搜索了一下,發現了,它有與CObject的類做是不可複製的或類似的東西這個!?!?...

有沒有人知道如何解決這個問題?

回答

2

CObject聲明拷貝構造函數爲private,所以你需要爲你自己的類實現拷貝構造函數(和賦值操作符重載)。 CObject constructor documentation說:

The standard C++ default class copy constructor does a member-by-member copy. The presence of the private CObject copy constructor guarantees a compiler error message if the copy constructor of your class is needed but not available. You must therefore provide a copy constructor if your class requires this capability.

我希望這有助於!

0

您是否曾在.cpp文件中忘記IMPLEMENT_SERIAL

+0

nope ...你讀過關於CObject構造的東西嗎? – Incubbus

相關問題