![](/img/trans.png)
[英]'CObject::CObject' : cannot access private member declared in class '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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.