[英]Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject'
I'm getting a strange error telling me that I cannot access private member declared in class 'CObject' when simply trying to pass a CStringArray to a function I have written to break it up into pieces. 我收到一个奇怪的错误告诉我,当我只是尝试将CStringArray传递给我编写的函数以将其分解为碎片时,我无法访问在类'CObject'中声明的私有成员。 I've commented out my entire function code so I know that the problem resides within the passing of the object itself, I'm assuming that I'm doing so incorrectly.
我已经注释掉了我的整个函数代码,所以我知道问题存在于对象本身的传递中,我假设我做错了。
Here is my code: 这是我的代码:
// 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);
Here is my CStringArrayHandler function: 这是我的CStringArrayHandler函数:
void CSDI1View::CStringArrayHandler(CStringArray arr)
{
// Left out code here since it is not the cause of the problem
}
Here is the declaration of the function in my header file: 这是我的头文件中的函数声明:
class CSDI1View : public CView
{
// Operations
public:
void CStringArrayHandler(CStringArray arr); // <<<<===================
And here is the full text of the error I am getting: 这是我得到的错误的全文:
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
错误1错误C2248:'CObject :: CObject':无法访问在类中声明的私有成员>'CObject'c:\\ program files(x86)\\ microsoft visual studio 12.0 \\ vc \\ atlmfc \\ include \\ afxcoll.h 590 1> SDI -1
You are passing CStringArray arr
by value, so the copy constructor for CStringArray
must be accessible. 您正在通过值传递
CStringArray arr
,因此必须可以访问CStringArray
的复制构造函数。 But it isn't, because CStringArray
inherits from CObject
which prohibits copying (that's what the compiler error message, which you actually didn't fully paste here, is saying) 但事实并非如此,因为
CStringArray
继承自CObject
,禁止复制(这就是编译器错误消息,你实际上并没有完全粘贴在这里)
The solution is to pass arr
by reference: 解决方案是通过引用传递
arr
:
void CStringArrayHandler(const CStringArray& arr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.