I am making a c++ program and I am stuck on the stage of hosting it on linux. (in fact it is an addon for node.js, but it does not matter now). I get an error when compiling my function on linux (on windows everything is OK).
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::string’ {aka ‘std::__cxx11::basic_string<char>’}
return(merge(messUp3(a.substr(0, (int)(a.size()) / 2)), messUp3(a.substr((int)(a.size()) / 2))));
the problem is exactly here: a.substr(0, (int)(a.size()) / 2)
. I have managed to fix the error by deleting & from arguments of functions. string merge(string& a, string& b)
-> string merge(string a, string b)
. I think I have some understanding, why it should not work with &, but then I get a complete misunderstanding of why does it work on windows? How do linux and windows gcc compilers differ? Or the problem is somewhere else?