1

Can I overload the assignment operator for a class with a const member? The following class is a minimal example, in my case, there is a private const string. The copy constructor is straightforward.

If I cannot provide an assignment operator, what can I do to make the compiler warning C4512 go away?

class cTest
{
public:
  cTest();
  cTest(int i);
  cTest(const cTest & other);
  cTest & operator= (const cTest& other);
private:
  const int m_i;
};

EDIT: The question remains: If I cannot provide an assignment operator, what can I do to make the compiler warning C4512 go away? Why does the warning arise?

Fabian
  • 4,001
  • 4
  • 28
  • 59
  • 1
    The dupe you received is valid. For some followup look [here](http://stackoverflow.com/questions/634662/non-static-const-member-cant-use-default-assignment-operator) and [here](http://stackoverflow.com/questions/4288190/constant-class-members-assignment-operator-and-qlist) – NathanOliver Apr 09 '15 at 13:26
  • The warning is there because a const member implicitly deletes the copy-constructor and copy-assignment operator. – David G Apr 09 '15 at 13:28

0 Answers0