Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject'

1.6k views Asked by At

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

1

There are 1 answers

4
Anton Savin On BEST ANSWER

You are passing CStringArray arr by value, so the copy constructor for CStringArray must be accessible. 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)

The solution is to pass arr by reference:

void CStringArrayHandler(const CStringArray& arr);