【发布时间】:2015-09-05 16:17:22
【问题描述】:
我正在尝试将项目从 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 的定义似乎也没有改变,这使它变得陌生。
这里报告了其他类似的问题,但我在那里找不到解决问题的方法。在大多数其他情况下,问题似乎来自缺少公共默认构造函数、复制构造函数或赋值运算符。
我们扩展 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 CArray 或 error using CArray 的副本 -> 在这些 CObject 派生类中缺少公共默认构造函数和复制构造函数。如上所述,我们的代码并非如此。
【问题讨论】:
-
GParameterValueList复制构造函数是什么样的?它是否会尝试委托给其基类的复制构造函数?CList没有可以委托的人。 -
不,复制构造函数遍历另一个列表,复制每个 ParameterValue 然后将其推送到当前列表的后面。普通的构造函数什么都不做,而 operator= 的作用与复制构造函数几乎相同。
-
一种或另一种方式,在您未显示的代码中的某处,正在调用
CList的复制构造函数。弄清楚在哪里以及如何。