class Example { public: int i; void would_compile() { this->i = 1; } void wont_compile() const { this->i = 2; } }; int main() { }
Standard input is empty
prog.cpp: In member function ‘void Example::wont_compile() const’: prog.cpp:14:11: error: assignment of member ‘Example::i’ in read-only object this->i = 2; ^
Standard output is empty