I have an interesting problem with gcc 4.5.2. Following code
#include<thread>
#include<iostream>
using std::cout;
void foo(int a){
cout<<a;
}
template <typename T>
void goo(void (*fn)(T),T c){
fn(c);
}
int main(void)
{
std::thread TH;
void (*ptr)(int)=foo;
TH= std::thread(goo<int>,ptr,1);
TH.join();
return 0;
}
.. will not compile on gcc 4.5.2 s error: cannot bind ‘void(void (*)(int), int)’ lvalue to ‘void (&&)(void (*)(int), int)’followed by a second errorinitializing argument 1 of ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void(void (*)(int), int), _Args = {void (*&)(int), int}]’
However, this code compiles when it templateis deleted, and also compiles with gcc 4.7.0 (with templatein place).
Even if this is a compiler problem, can someone explain what the error is? I would be happy to find a way to do the binding (even if it is, say, automatic in gcc 4.7).
source
share