我在VS13中编写多个线程
功能声明:
void getColorImage(HANDLE &colorEvent, HANDLE &colorStreamHandle, Mat &colorImage);
void getDepthImage(HANDLE &depthEvent, HANDLE &depthStreamHandle, Mat &depthImage);
void getSkeletonImage(HANDLE &skeletonEvent, Mat &skeletonImage, Mat &colorImage, Mat &depthImage, ofstream& myfile);
int main()
{
// this is inside a while loop
std::thread first(getColorImage, colorEvent, colorStreamHandle, colorImage);
std::thread second(getDepthImage, depthEvent, depthStreamHandle, depthImage);
std::thread third(getSkeletonImage, skeletonEvent, skeletonImage, colorImage, depthImage, myfile);
first.join();
second.join();
third.join();
}
然而,我收到错误:
错误1错误C2280:'std :: basic_ofstream> :: basic_ofstream(const std :: basic_ofstream>&)':尝试引用已删除的函数c:\ program files(x86)\ microsoft visual studio 12.0 \ vc \ include \ type_traits 1545 1 Skeleton_RGBDepth_DataAcquisition2013
不知道为什么......有人可以帮忙吗?
答案 0 :(得分:1)
std::thread
构造函数与std::bind
相同,按值获取其所有参数。但是std::ofstream
有一个delete
d拷贝构造函数,因此出错了。
使用std::ref
包裹所有应通过引用传递的参数。