この質問は、オブジェクト参照引数をスレッド関数に渡すとコンパイルに失敗するのはなぜですか? .
同様の問題が発生しましたが、私の場合、ファンクターはテンプレートです。
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 言います:
error: no match for 'operator<<' in 'out << "hi\012"'
どうすればこの問題を解決できますか?