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. 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:
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
You are passing
CStringArray arr
by value, so the copy constructor forCStringArray
must be accessible. But it isn't, becauseCStringArray
inherits fromCObject
which prohibits copying (that's what the compiler error message, which you actually didn't fully paste here, is saying)The solution is to pass
arr
by reference: