gpt4 book ai didi

c++ - 尝试传递 CStringArray 时出现错误,无法访问类 'CObject' 中声明的私有(private)成员

转载 作者:太空狗 更新时间:2023-10-29 20:39:40 24 4
gpt4 key购买 nike

我收到一个奇怪的错误,告诉我在简单地尝试将 CStringArray 传递给我编写的将其分解成多个部分的函数时,我无法访问类“CObject”中声明的私有(private)成员。我已经注释掉了我的整个函数代码,所以我知道问题出在对象本身的传递中,我假设我这样做不正确。

这是我的代码:

    // If successful, read file into CStringArray
CString strLine;
CStringArray lines;
while (theFile.ReadString(strLine))
{
lines.Add(strLine);
}

// Close the file, don't need it anymore
theFile.Close();

// Break up the string array and separate it into data
CStringArrayHandler(lines);

这是我的 CStringArrayHandler 函数:

void CSDI1View::CStringArrayHandler(CStringArray arr)
{
// Left out code here since it is not the cause of the problem
}

这是我的头文件中函数的声明:

class CSDI1View : public CView
{
// Operations
public:
void CStringArrayHandler(CStringArray arr); // <<<<===================

这是我收到的错误的全文:

Error 1 error C2248: 'CObject::CObject' : cannot access private member declared in class >'CObject' c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afxcoll.h 590 1 >SDI-1

最佳答案

您正在按值传递 CStringArray arr,因此 CStringArray 的复制构造函数必须可访问。但事实并非如此,因为 CStringArray 继承自 CObject ,它禁止复制(这就是编译器错误消息的意思,您实际上并没有完全粘贴在这里)

解决方案是通过引用传递arr:

void CStringArrayHandler(const CStringArray& arr);

关于c++ - 尝试传递 CStringArray 时出现错误,无法访问类 'CObject' 中声明的私有(private)成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27052268/

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