#include <iostream> #include <string> class User { public: std::string& name() { return name_; } private: std::string name_ ; }; int main() { const User user ; std::cout << user.name() << '\n' ; }
Standard input is empty
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' ; ^
Standard output is empty