【发布时间】:2018-03-12 12:28:53
【问题描述】:
我是线程处理的新手,我有点困惑为什么这段代码不起作用:
// Note that the GKITH object is useful for my whole code
void thread_function( gkit2light_Handler*& GKITH )
{
std::cout << "\t~ Writing from gkit2light thread..." << std::endl;
}
int main( int argc, char** argv )
{
// Custom gkit2light Handler
gkit2light_Handler *gkit_handler = new gkit2light_Handler( );
// Launching thread...
std::thread gkit_thread( thread_function, gkit_handler );
return 0;
}
我使用 XCode 9 在 macOS 10.13 下运行它。 这些行实际上都没有给我一个错误,但我的编译器给了我这个消息:«尝试使用已删除的函数»。 这很奇怪,因为这里的 thread_function() 只访问标准输出...
这里是删除的功能,也许对你有帮助!
struct __nat
{
#ifndef _LIBCPP_CXX03_LANG
// ...
// This is the destructor that is throwing the error
~__nat() = delete;
#endif
};
这是错误的屏幕截图(没有更多信息): XCode compiler error screenshot
【问题讨论】:
-
编译器抱怨哪一行? (请edit该问题包含整个编译器错误消息。)
-
好吧,我需要为并行计算(图像处理)创建一个线程,但是因为我遇到了这个错误,我试图简化代码并以这个结束,仍然给我同样的错误!跨度>
-
你错了。那里有额外的信息。哪个是
main.cpp第 9 行? (另外,请学习如何显示实际的编译器输出,而不是将其复制到问题中。)
标签: c++ multithreading