试图传递CStringArray给出错误无法访问类'CObject'中声明的私有成员

Jay*_*ayB 3 c++ mfc compiler-errors cstring visual-studio-2013

我收到一个奇怪的错误告诉我,当我只是尝试将CS​​tringArray传递给我编写的函数以将其分解为碎片时,我无法访问在类'CObject'中声明的私有成员.我已经注释掉了我的整个函数代码,所以我知道问题存在于对象本身的传递中,我假设我做错了.

这是我的代码:

    // 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);
Run Code Online (Sandbox Code Playgroud)

这是我的CStringArrayHandler函数:

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

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

class CSDI1View : public CView
{
// Operations
public:
    void CStringArrayHandler(CStringArray arr);   // <<<<===================
Run Code Online (Sandbox Code Playgroud)

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

错误1错误C2248:'CObject :: CObject':无法访问在类中声明的私有成员>'CObject'c:\ program files(x86)\ microsoft visual studio 12.0\vc\atlmfc\include\afxcoll.h 590 1> SDI -1

Ant*_*vin 5

您正在传递CStringArray arr值,因此CStringArray必须可以访问复制构造函数.但它不是,因为CStringArray继承CObject禁止复制(这是编译器错误消息,你实际上没有完全粘贴在这里,说)

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

void CStringArrayHandler(const CStringArray& arr);
Run Code Online (Sandbox Code Playgroud)