#include <iostream> class ob { public: std::string s; auto & getter4() const { return s; } }; int main() { ob const s; std::string & t = s.getter4(); t = "test"; std::cout << s.s; return 0; }
Standard input is empty
prog.cpp: In function ‘int main()’: prog.cpp:11:29: error: binding reference of type ‘std::__cxx11::string&’ {aka ‘std::__cxx11::basic_string<char>&’} to ‘const std::__cxx11::basic_string<char>’ discards qualifiers std::string & t = s.getter4(); ~~~~~~~~~^~
Standard output is empty