In "The C++ Programming Language Fourth Edition" by "Bjarne Stroustrup",5.3.2. Passing Arguments, there is a code segment:
void f(vector<double>& v); // function do something with v
int main()
{
vector<double> some_vec {1,2,3,4,5,6,7,8,9};
thread t1 {f,some_vec};
}
the declaration of f in first line dont have a const parameter. When I try the following similar code :
void f(string& str) { cout << str << endl; }
int main()
{
string fstr="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
thread t1 {f,fstr};
}
I got the following error:
/usr/include/c++/4.8/functional: In instantiation of ‘struct std::_Bind_simple<void (*(std::basic_string<char>))(std::basic_string<char>&)>’:
/usr/include/c++/4.8/thread|137 col 47| required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(std::basic_string<char>&); _Args = {std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’
so what is going on here?
BTW: if I call f directly, then everything is OK