'CObject::CObject' : cannot access private member declared in class 'CObject'd:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h
This error happens while trying to send the instance of CTypedPointerList in the function parameter from one class to another class.
How to solve this issue?
Here is my code
ObjectList.h
#pragma once
#include "LogData.h"
typedef CTypedPtrArray<CPtrList , CLog *> CLogData;
class CObjectList
{
public:
CLogData m_logData;
public:
CObjectList();
CLogData GetLog();
};
开发者_开发百科
ObjectList.cpp
#include "stdafx.h"
#include "LogData.h"
CObjectList::CObjectList()
{
}
CLogData CObjectList::GetLog()
{
return m_logData;
}
Regards,
karthik
I'd need to see your code to be sure, but it looks like you're trying to pass the CTypedPointerList by value. This means a copy of the instance needs to be created, thus the implicit call to the copy constructor. The authors of CTypedPointerList have marked the copy constructor private in order to indicate that copies of this class cannot be made.
Try passing by reference (perhaps a const reference?). If you truly do need a copy, you may need to do this manually.
EDIT
Ahh... you're using the instance as a return value. The GetLog() method returns a copy of the instance, and since the instance cannot be copied, it does not compile. I expect what you really want to do is return a const reference to the instance. This means client will get a read-only reference to the log, no copy is made. To achieve this, change the return type of GetLog()
to const CLogData &
in both the h and cpp files.
精彩评论