fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void print_indented_const(std::size_t dist, const std::string& s)
  5. {
  6. std::cout << std::string(dist, ' ') << s << '\n' ;
  7. }
  8.  
  9. void print_indented(std::size_t dist, std::string& s)
  10. {
  11. print_indented_const(dist, s);
  12. }
  13.  
  14. int main()
  15. {
  16. print_indented(5, "some text"); // illegal
  17. print_indented_const(5, "some text"); // legal
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:34: error: invalid initialization of non-const reference of type ‘std::string& {aka std::basic_string<char>&}’ from an rvalue of type ‘const char*’
     print_indented(5, "some text");  // illegal
                                  ^
prog.cpp:9:6: error: in passing argument 2 of ‘void print_indented(std::size_t, std::string&)’
 void print_indented(std::size_t dist, std::string& s)
      ^
stdout
Standard output is empty