error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'


  • struct SConfig


    CString m_strAppMode; // Production or Engineering

    CString m_strUIMode; // Hardware or Simulation

    CMap<CString, CString&, CString, CString&> MapKeyCmd;

    void init(void);


    The above code is giving the compilation error  as below:
    1>C:\Win16App\VisualStudio2005\VC\atlmfc\include\afxtempl.h(1339) : error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'

    1> C:\Win16App\VisualStudio2005\VC\atlmfc\include\afx.h(559) : see declaration of 'CObject::operator ='

    1> C:\Win16App\VisualStudio2005\VC\atlmfc\include\afx.h(529) : see declaration of 'CObject'

    1> This diagnostic occurred in the compiler generated function 'CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &CMap<KEY,ARG_KEY,VALUE,ARG_VALUE>::operator =(const CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &)'

    1> with

    1> [

    1> KEY=CString,

    1> ARG_KEY=CString &,

    1> VALUE=CString,

    1> ARG_VALUE=CString &

    1> ]

    Can any body help me what is the reason behind this and how can I fix this?


    Friday, December 05, 2008 5:26 PM


  • I cannot believe that the above code by itself is giving you this error.

    CString is not derived from CObject. Are you perhaps trying to use operator = on your SConfig struct? If so, you are running into the fact that CMap is not copyable or assignable, because the base class CObject is not.

    I would strongly recommend you to use std::map rather than CMap. It is copyable, assignable, generally better designed, and portable. Superior in every imaginable way, IMHO.

    David Wilkinson | Visual C++ MVP
    Friday, December 05, 2008 6:56 PM