Boost :: thread thread()不接受参数 [英] Boost::thread thread() not accepting arguments

查看:124
本文介绍了Boost :: thread thread()不接受参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IDE向我抱怨说线程不包含我传递给它的参数数量.我相信这是因为它们太多了...

The IDE complains to me that thread does not contain the number of parameters that I am passing it. This is because there are too many of them, I believe...

当我将标准库用于线程时遇到了同样的问题,但是对于兼容性问题,我需要使用Boost :: threads. HERE 是我上一个问题的链接,有人解释说这个问题是由引起的通过垂直模板.

I had this same issue when I was using the standard library for threads, but do to compatibility issues, I need to use the Boost::threads. HERE is the link to my previous question where someone explained that the issue was caused by veriadic templates.

这确实是一个问题,但是,切换到增强线程后,该错误又回来了,更改veriadic max不能解决该问题.

This was indeed the issue, however, after switching to boost threads, that error comes back and changing the veriadic max does not fix it.

这是我的线程声明

boost::thread db(writeToDB, coordString, time, std::to_string(id), imageName, azimuth, att_pitch, att_roll, yaw, cam_pitch, cam_roll);

这是我尝试绑定函数的方式:

Here is how I tried the bind function:

boost::thread db(boost::bind(::writeToDB, coordString, time, std::to_string(id), imageName, azimuth, att_pitch, att_roll, yaw, cam_pitch, cam_roll));

当前的IDE是Visual Studio 2013,但是它需要与Visual Studio 2008兼容

And the current IDE is Visual Studio 2013, however it needs to be compatible with Visual Studio 2008

这也是我收到的实际错误:

Also here is the actual error I am recieveing:

错误:

Error 6 error C2661: 'boost::thread::thread' : no overloaded function takes 11 arguments c:\users\hewittjc\desktop\final project\project1\clientexample.cpp 174 1 Project1

Error 6 error C2661: 'boost::thread::thread' : no overloaded function takes 11 arguments c:\users\hewittjc\desktop\final project\project1\clientexample.cpp 174 1 Project1

推荐答案

Boost.Thread(内部利用Boost.Bind绑定参数)仅支持 some 固定数量的参数( doc ):

Boost.Thread (that internally exploits Boost.Bind for binding arguments) supports only some fixed number of arguments (doc):

带有参数的线程构造器

template <class F,class A1,class A2,...>
thread(F f,A1 a1,A2 a2,...);

前提条件:

F和每个An必须是可复制的或可移动的.

F and each An must be copyable or movable.

效果:

就像thread(boost::bind(f,a1,a2,...))一样.因此,f和每个an被复制到内部存储器中以供新线程访问.

As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread.

后置条件:

*this指的是新创建的执行线程.

*this refers to the newly created thread of execution.

投掷:

boost::thread_resource_error如果发生错误.

错误条件:

resource_unavailable_try_again:系统缺少创建另一个线程的必要资源,否则将超出系统对进程中线程数的限制.

resource_unavailable_try_again : the system lacked the necessary resources to create an- other thread, or the system-imposed limit on the number of threads in a process would be exceeded.

注意:

除功能f之外,当前最多可以指定9个附加参数a1a9.

Currently up to nine additional arguments a1 to a9 can be specified in addition to the function f.

很明显,这意味着传递 11 参数(如您所做的那样)必须导致您看到以下错误:没有重载函数需要11个参数" .

Clearly, this means that passing 11 arguments (as you do) must result in the error you see: "no overloaded function takes 11 arguments".

不幸的是,没有简单的方法来扩展限制.可能的解决方案是:

Unfortunately, there is no easy way of extending the limit. Possible solutions are:

  • 减少参数的总数(仅超出限制一个)

  • reducing the overall number of arguments (you're only one ahead of the limit)

使用其他库来绑定参数,例如

using other library for binding arguments like Boost.Phoenix

将参数包装在类类型的变量中(或至少其中一些)

wrapping arguments in a class-type variable (or at least some of them)

在完全支持 variadic模板的C ++ 11编译器上切换到std::thread.

switching to std::thread on a C++11 compiler that fully supports variadic templates.

这篇关于Boost :: thread thread()不接受参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆