Im trying to return a CStringArray:
In my “.h” I defined:
Private:
CStringArray array;
public:
CStringArray& GetArray();
In . cpp I have:
CQueue::CQueue()
{
m_hApp = 0;
m_default = NULL;
}
CQueue::~CQueue()
{
DeleteQueue();
}
CStringArray& CQueue::GetArray()
{
return array;
}
From another file I’m trying to call it by:
CStringArray LastUsedDes = cqueue.GetArray();
I guess it is because of the above line that I get the error:
error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
The problem is on this line
Even though you’re returning a reference to the
CStringArrayin theGetArray()function a copy of the array is being made in the line above.CStringArrayitself doesn’t define a copy constructor and it derives fromCObject, which has a private copy constructor.Change the line to
But be aware that
LastUsedDesnow refers to the sameCStringArraycontained in your class instance, and any changes made to one will be visible in the other.If you need a local copy of the returned array you can use the
Appendmember function to copy the contents.