【发布时间】:2017-11-28 00:07:04
【问题描述】:
我有一个在线程上写入文件的类
class A{
public:
void writeToFile(ofstream& outFile, obj &a)
{
//...
}
thread memberThread1(ofstream& outFile, obj &a)
{
cout << "Thread 1 is now running " << endl;
return thread ([=]{ writeToFile(outFile, a);});
}
};
我在 lambda 函数上遇到了一些错误。
无法将参数 1 从“const std::ofstream”转换为“std::ofstream” &'
注意:转换失去限定符
我能够通过执行const_cast 来修复第二个参数a,但我不知道如何修复第一个参数。
谢谢!
【问题讨论】:
标签: c++ multithreading lambda