MSDN > フォーラム ホーム > Visual C++ Language > Compiler Error : error C2248
質問する質問する
 

質問Compiler Error : error C2248

  • 2009年11月2日 5:31krshn.acharya ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
     error C2248: 'CObject::operator =' : cannot access private member declare class 'CObject'
         S:\MedCom\extern\i586-WinNT5.01\Microsoft Visual Studio\VC\atlmfc\include\afx.h(552) : see declaration of 'CObject::operator ='
         S:\MedCom\extern\i586-WinNT5.01\Microsoft Visual Studio\VC\atlmfc\include\afx.h(522) : see declaration of 'CObject'
         This diagnostic occurred in the compiler generated function 'CArray<TYPE,ARG_TYPE> &CArray<TYPE,ARG_TYPE>::operator =(const CArray<TYPE,ARG_TYPE> &)'

    I am not able to compile this code in VC9 which was working fine in VC6.

    Code:

    Class XYZ
    {
    private:
    CArray<Cap3dStringDataTag,Cap3dStringDataTag&> myTagList;
    }
    Please help me find whats wrong in this.

    Regards,
    Krishna

すべての返信

  • 2009年11月2日 6:28Naveen R ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    This is because in your code some where you might be assigning an object of XYZ to another object of XYZ.

    Either you have to remove the assignment of object or write your own =operator for this class.
    Nave [My Blog]
  • 2009年11月2日 6:52WayneAKing ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    If the code was working in VC6 then it's possible you are being affected
    by one of the many changes made from VC6 up to VC9. Each new version
    usually has changes which may break existing code. You need to read
    carefully the documentation on "Breaking Changes" for each new release:

    Breaking Changes in Visual C++ .NET 2003

    The Visual C++ compiler has significantly increased its conformance
    with the C++ standard in the Visual Studio .NET 2003 release. With
    this conformance comes a number of breaking changes. Many of those
    changes now result in compiler errors, where no compiler errors were
    given in previous releases. However, there are also a number of silent,
    or runtime errors, which are described in this section.

    http://msdn.microsoft.com/en-us/library/ms177251.aspx



    Breaking Changes in the Visual C++ 2005 Compiler

    This topic discusses the behavior changes in Visual C++ 2005
    that can cause code that worked in a previous release to
    either not compile, or to behave differently at run time.

    http://msdn.microsoft.com/en-us/library/ms177253.aspx



    Breaking Changes

    This topic lists the breaking changes in Visual C++ 2008.

    http://msdn.microsoft.com/en-us/library/bb531344.aspx

    - Wayne

  • 2009年11月4日 5:35Nancy ShaoMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    Hi Krishna,

     

    Please refer to this article with link:

     

    http://msdn.microsoft.com/en-us/library/ccb3dh5c.aspx

     

    As this article saysthe reason for the compiler errors is that CObject declares a private copy constructor and assignment operator in the AFX.h file. Consequently, the compiler does not generate a default copy constructor and assignment operator for the CObject-derived class. Because the compiler does not find these functions declared in the class, it reports the errors.

     

    To avoid the compiler errors, you need to implement a copy constructor and assignment operator for the CObject-derived class. This is illustrated in the sample code below. You can avoid the errors by uncommenting the lines indicated in the sample code.

     

    Best Regards,

    Nancy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.