cannot access private member error when porting MFC project
On the forum, we have surfaced another error. I had a chance today to see a real-world code with this error and actually to narrow down the problem. So if you see an error like
1>c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(259) : error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(540) : see declaration of 'CObject::operator ='
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(510) : see declaration of 'CObject'
1> This diagnostic occurred in the compiler generated function 'CGdiObject &CGdiObject::operator =(const CGdiObject &)'
The cause of this error is that you are have a class like
class CReproClass {
public:
CReproClass::CReproClass(void) {}
CReproClass::~CReproClass(void) {}
CPen m_pen; //or any other class that subclasses CGdiObject
};
or
class CReproClass : public CPen{
...
};
then is later used in
CReproClass a;
CReproClass b;
a = b;
This is the cause of the problem.
Comments
Anonymous
March 26, 2007
Thanks for the help, this saved me hours!Anonymous
May 19, 2008
The comment has been removedAnonymous
August 05, 2008
Hey dude, thank you so much for this!!! I've been looking everywhere for a simple, yet comprehensive explanation for this compilation error, and nothing can be found. This really hits the spot. Thank you so much for this!!Anonymous
October 22, 2008
Here is my problem similar ti this. i have written a code to update my combo box content to my local structure.Something like following.At this point the error is comming. void CMeterpollingConfiguration::getMeterPoolingConfigData() { #if 1 COleDateTime DateTime; sprintf(g_stMeterpollingconf.cDateTimeBC,"%04d-%02d-%02d %02d:%02d:%02d", DateTime.GetYear(), DateTime.GetMonth(), DateTime.GetDay(), DateTime.GetHour(), DateTime.GetMinute(), DateTime.GetSecond()); #endif if(m_MeterpollingBillingData == TRUE) { g_stMPCTypeofdata.cbMPCBMinute = m_MpcBdMinutes; g_stMPCTypeofdata.csMPCBSubminutes = m_MpcBdMinute; g_stMPCTypeofdata.cbMPCBHours = m_MpcBdHours; g_stMPCTypeofdata.cbMPCBDay = m_MpcBdDay; g_stMPCTypeofdata.cbMPCBDate = m_MpcBdDate; } else if(m_MpcLoadServyData == TRUE) { g_stMPCTypeofdata.cbMPCBMinute = m_MpcLsdMinutes; g_stMPCTypeofdata.csMPCBSubminutes = m_MpcLsdMinute;//m_MpcLsdMinute g_stMPCTypeofdata.cbMPCBHours = m_MpcLsdHours; g_stMPCTypeofdata.cbMPCBDay = m_MpcLsdDay; g_stMPCTypeofdata.cbMPCBDate = m_MpcLsdDate; } else if(m_MPCFullData == TRUE) { g_stMPCTypeofdata.cbMPCBMinute = m_MpcFdMinutes; g_stMPCTypeofdata.csMPCBSubminutes = m_MpcFdminute;//m_MpcLsdMinute g_stMPCTypeofdata.cbMPCBHours = m_MpcFdHours; g_stMPCTypeofdata.cbMPCBDay = m_MpcFdDay; g_stMPCTypeofdata.cbMPCBDate = m_MpcFdDate; } else if(m_MpcTamperData == TRUE) { g_stMPCTypeofdata.cbMPCBMinute = m_MpcTdMinutes; g_stMPCTypeofdata.csMPCBSubminutes = m_MpcTdMinute;//m_MpcLsdMinute g_stMPCTypeofdata.cbMPCBHours = m_MpcTdHours; g_stMPCTypeofdata.cbMPCBDay = m_MpcTdDay; g_stMPCTypeofdata.cbMPCBDate = m_MpcTdDate; } else if(m_MpcInstData == TRUE) { g_stMPCTypeofdata.cbMPCBMinute = m_MpcIdMinutes; g_stMPCTypeofdata.csMPCBSubminutes = m_MpcIdMinute;//m_MpcLsdMinute g_stMPCTypeofdata.cbMPCBHours = m_MpcIdHours; g_stMPCTypeofdata.cbMPCBDay = m_MpcIdDay; g_stMPCTypeofdata.cbMPCBDate = m_MpcIdDate; } else {} return; } here pls note that :i'm updating different combo box content to same structure variables,by using if...else if ..else statement. while compilation i 'm getting error " 'CObject::operator =' : cannot access private member declared in class 'CObject'" which is in compiler genetated file(afxwin.h). Pls help me to slove this problem. Thanks.Anonymous
March 08, 2009
The comment has been removed