fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void fun1( const std::string& strParm )
  5. {
  6. std::cout << "In [void fun1( const std::string& strParm )] :: " << strParm << std::endl;
  7. }
  8.  
  9.  
  10. void fun2( std::string& strParm )
  11. {
  12. std::cout << "In [void fun2( std::string& strParm )] :: " << strParm << std::endl;
  13. }
  14.  
  15. int main()
  16. {
  17. std::string strValue1 = "Hello ";
  18. std::string strValue2 = "World!!!";
  19.  
  20. fun1( strValue1 + strValue2 ); // Ok
  21. fun2( strValue1 ); // Ok
  22. fun2( strValue1 + strValue2 ); // Compilation error
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0.01s 5504KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:18: error: cannot bind non-const lvalue reference of type ‘std::__cxx11::string&’ {aka ‘std::__cxx11::basic_string<char>&’} to an rvalue of type ‘std::__cxx11::basic_string<char>’
  fun2( strValue1 + strValue2 ); // Compilation error
        ~~~~~~~~~~^~~~~~~~~~~
prog.cpp:10:6: note:   initializing argument 1 of ‘void fun2(std::__cxx11::string&)’
 void fun2( std::string& strParm )
      ^~~~
stdout
Standard output is empty