fork download
  1. class Example
  2. {
  3. public:
  4.  
  5. int i;
  6.  
  7. void would_compile()
  8. {
  9. this->i = 1;
  10. }
  11.  
  12. void wont_compile() const
  13. {
  14. this->i = 2;
  15. }
  16. };
  17.  
  18. int main()
  19. {
  20. }
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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;
           ^
stdout
Standard output is empty