+ 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
    Posts
    43

    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"

    Code:
    class CMyData
    {
    public:
    	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:
    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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