gpt4 book ai didi

c++ - VS2013 编译器 : 'CObject::CObject' : cannot access private member declared in class 'CObject'

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:49:57 27 4
gpt4 key购买 nike

我正在尝试在 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 的定义似乎也没有改变,这使它变得更加陌生。

这里报告了其他类似的问题,但我在那里找不到解决我的问题的方法。在大多数其他情况下,问题似乎来自缺少公共(public)默认构造函数、复制构造函数或赋值运算符。

我们扩展 CList 的类提供了所有这些的公共(public)版本,而 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 派生类中缺少公共(public)默认和复制构造函数。如上所述,我们的代码不是这种情况。

最佳答案

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

或者,尝试使用指针列表,例如 CList<ParameterValue*, ParameterValue*&> .

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

关于c++ - VS2013 编译器 : 'CObject::CObject' : cannot access private member declared in class 'CObject' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30942242/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com