尝试传递 CStringArray 给出错误无法访问在类"CObject"中声明的私有成员
Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject'
我收到一个奇怪的错误,告诉我当只是尝试将CStringArray传递给我编写的函数以将其分解为碎片时,我无法访问在类"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);
这是我的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); // <<<<===================
这是我得到的错误全文:
错误1 错误 C2248:"CObject::CObject":无法访问类>"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);
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 错误 C2248:'CObject::CObject':无法访问类 'CObject' afxwin.h 中声明的私有成员
- 尝试传递 CStringArray 给出错误无法访问在类"CObject"中声明的私有成员
- 'CObject::CObject':无法访问类 'CObject' 中声明的私有成员
- 无法访问在类"CObject"中声明的私有成员?