【问题标题】:VS2013 compiler: 'CObject::CObject' : cannot access private member declared in class 'CObject'VS2013 编译器:“CObject::CObject”:无法访问在“CObject”类中声明的私有成员
【发布时间】: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 CArrayerror using CArray 的副本 -> 在这些 CObject 派生类中缺少公共默认构造函数和复制构造函数。如上所述,我们的代码并非如此。

【问题讨论】:

  • GParameterValueList 复制构造函数是什么样的?它是否会尝试委托给其基类的复制构造函数? CList 没有可以委托的人。
  • 不,复制构造函数遍历另一个列表,复制每个 ParameterValue 然后将其推送到当前列表的后面。普通的构造函数什么都不做,而 operator= 的作用与复制构造函数几乎相同。
  • 一种或另一种方式,在您未显示的代码中的某处,正在调用CList 的复制构造函数。弄清楚在哪里以及如何。

标签: c++ c++11 mfc


【解决方案1】:

我认为问题出在您的 ParameterValue 类中。尝试在其中声明 public 构造函数,包括默认构造函数。 在我看来,CList 试图在某处调用 ParameterValue 构造函数,但前者不能,因为后者是私有的。

或者,尝试使用指针列表,例如CList&lt;ParameterValue*, ParameterValue*&amp;&gt;

另一种选择是使用 std 容器而不是 CList。

【讨论】:

    猜你喜欢
    • 2013-04-24
    • 2011-09-06
    • 2015-05-05
    • 1970-01-01
    • 2013-07-28
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    相关资源
    最近更新 更多