fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class test {
  5. int a;
  6. mutable int b;
  7.  
  8. void foo() const { a = 14; } // blad kompilacji, metoda nie moze zmieniac nic w klasie
  9.  
  10. void boo() { a = 14; } // ok
  11.  
  12. void bar() const { b = 14; } // ok, pole b jest mutable
  13. };
  14.  
  15.  
  16. int main() {
  17.  
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'void test::foo() const':
prog.cpp:8:23: error: assignment of member 'test::a' in read-only object
  void foo() const { a = 14; } // blad kompilacji, metoda nie moze zmieniac nic w klasie
                       ^
stdout
Standard output is empty