fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class User
  5. {
  6. public:
  7. std::string& name() { return name_; }
  8.  
  9. private:
  10. std::string name_ ;
  11. };
  12.  
  13. int main()
  14. {
  15. const User user ;
  16. std::cout << user.name() << '\n' ;
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:28: error: passing ‘const User’ as ‘this’ argument of ‘std::string& User::name()’ discards qualifiers [-fpermissive]
     std::cout << user.name() << '\n' ;
                            ^
stdout
Standard output is empty