![](/img/trans.png)
[英]'CObject::CObject' : cannot access private member declared in class 'CObject'
[英]VS2013 compiler: 'CObject::CObject' : cannot access private member declared in class 'CObject'
我正在嘗試將項目從Visual Studio遷移到c ++ 11。 我修復了許多問題,但還有一個我似乎無法用MFC破解的問題:
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的定義似乎也沒有改變,這使得它變得陌生。
這里還報告了其他類似的問題,但是我在那里找不到我的問題的解決方案。 在大多數其他情況下,問題似乎是由於缺少公共默認構造函數,Copy構造函數或賦值運算符引起的。
但是,擴展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);
}
任何幫助,將不勝感激。
PS我們的實現已導出到DLL,我想知道這是否會引起一些沖突?
編輯:不是重復使用CArray的錯誤或使用CArray的 錯誤 ->在這些CObject派生類中缺少公共默認值和副本構造函數。 如上所述,我們的代碼並非如此。
我認為問題出在您的ParameterValue類中。 嘗試在其中聲明公共構造函數,包括默認構造函數。 在我看來,CList試圖在某個地方調用ParameterValue構造函數,但是前者不能,因為后者是私有的。
或者,嘗試使用指針列表,例如CList<ParameterValue*, ParameterValue*&>
。
另一種選擇是使用std容器而不是CList。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.