+ Reply to Thread
Results 1 to 2 of 2

Thread: What is "assignment operator could not be generated" warning?

  1. #1
    Junior Member
    Join Date
    Apr 2012

    What is "assignment operator could not be generated" warning?

    I am building following example using VC++ 2005.

    Compiler raises a warning: "warning C4512: 'CMyData' : assignment operator could not be generated"

    class CMyData
    	const int m_MyData ;
    	CMyData(int ndata) : m_MyData(ndata)
    	int GetData()
    		return m_MyData ;
    } ;
    What is this warning about?

    Can anyone explain me?

  2. #2
    Compiler synthesize its own assignment operator if required.

    But this is not the case all the time.

    In some cases, compiler thinks that it is not safe to synthesize assignment operator for the given class.

    In your case:
    Because const data items cannot be modified after initialization, if the class contains a const item, the default assignment operator would not work.

    For more information:

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts