This question might be related to Why does passing object reference arguments to thread function fails to compile?.
I encountered a similar problem, however, in my case the functor is a template.
class A {
public:
// Non template version works as expected!!.
// void operator()(std::ostream& out){
// out << "hi\n";
// }
// template version doesn't.
template <class Ostream>
void operator()(Ostream& out){
out << "hi\n";
}
};
int main() {
A a;
thread t(a, ref(cout));
t.join();
}
GCC says:
error: no match for 'operator<<' in 'out << "hi\012"'
How can I solve this problem?