#include <iostream>using namespace std; class Example {public: int x; int GetX() const { // GetX is a constant member function x = x + 1; // This causes an error return x; }}; int main() { Example y; y.x = 5; std::cout << y.GetX() << std::endl; return 0;}
Standard input is empty
prog.cpp: In member function ‘int Example::GetX() const’: prog.cpp:8:14: error: assignment of member ‘Example::x’ in read-only object x = x + 1; // This causes an error ^
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!