2015-06-19 132 views
2

我試圖將項目從Visual Studio中遷移到C++ 11。我固定的一些問題,但是有一個剩餘的我似乎不能與MFC破解:VS2013編譯器:'CObject :: CObject':無法訪問類'CObject'中聲明的私有成員

error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' (file.cpp) 
: see declaration of 'CObject::CObject' 
: see declaration of 'CObject' 
This diagnostic occurred in the compiler generated function 'CList<ParameterValue,ParameterValue &>::CList(const CList<ParameterValue,ParameterValue &> &)' 

這是一個已經不是我們的最終變化,針對Visual Studio的時候已經編制精碼2010工具集。從我可以收集的信息來看,似乎CObject的定義並沒有改變,這使得它變得陌生。

還有其他類似的問題在這裏報告,但我找不到解決我的問題。在大多數情況下,它會出現缺少公共缺省構造函數,複製構造函數或賦值運算符的問題。

然而,我們擴展CList的類提供了所有這些的公共版本,並且ParameterValue不會從CObject繼承。

class __declspec(dllexport) GParameterValueList : public CList<ParameterValue, ParameterValue&> 
{ 
// ParameterValue is a struct that DOES NOT inherit from CObject (or anything) 
public: 
    GParameterValueList(); 
    GParameterValueList(const GParameterValueList& SrcList); 
    GParameterValueList& operator=(const GParameterValueList& SrcList); 
} 

任何幫助,將不勝感激。

P.S.我們的實現被導出到DLL中,我想知道這是否會導致一些衝突?

編輯:不是error using CArrayerror using CArray - >在這些CObject派生類缺少公共默認和複製構造函數的副本。如上所述,我們的代碼並非如此。

+0

GParameterValueList複製構造函數的外觀是什麼樣的?是否嘗試委託給其基類的拷貝構造函數? 'CList'沒有一個委託給。 –

+0

不,複製構造函數會遍歷另一個列表,複製每個ParameterValue,然後將其推送到當前列表的後面。正常的構造函數什麼都不做,而operator =和copy構造函數幾乎一樣。 – Zepee

+0

不管怎樣,在你沒有顯示的代碼中,'CList'的拷貝構造函數被調用。找出在哪裏以及如何。 –

回答

0

我認爲問題出在你的ParameterValue類中。嘗試在那裏聲明public構造函數,包括默認的構造函數。 在我看來,CList嘗試在某處調用ParameterValue構造函數,但前者不能,因爲後者是私有的。

或者,嘗試使用指針列表,如CList<ParameterValue*, ParameterValue*&>

另一種替代方法是使用std容器而不是CList。

相關問題