c++ - 使用带参数的 Boost::Thread 时出现编译器错误

标签 c++ boost

我将不胜感激任何帮助。我试图用 Boost::Thread 异步调用一个函数,但出现了一些错误。这是我的真实代码。

主要内容:

vector<std::string> a = ...;
vector<std::string> b = ...;
vector<boost::thread> threads;

threads.push_back(boost::thread(do_work, an_integer, a[i], b.begin(), b.end()));

// Later I will join()...

其他地方:

void do_work(int i, std::string a_string, vector<string>::iterator begin, vector<string>::iterator end)
{
    // Some stuff
}

我对这些东西很陌生,更习惯于 C#。无论如何,这些是我得到的错误:

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 1 from 'std::_Vector_iterator<_Myvec>' to 'int'

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 3 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'std::_Vector_iterator<_Myvec>'

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 4 from 'std::_Vector_iterator<_Myvec>' to 'std::_Vector_iterator<_Myvec>'

如果您能提供任何帮助,我将不胜感激。我几乎可以肯定正在做一些极其愚蠢的事情!非常感谢。

最佳答案

那个编译器错误说 b.begin()b.end() 是不同的类型,这显然不能在你列出的代码中.重新检查您的代码以确保您没有将 b 定义为其他内容。 (还要检查 an_integer,因为编译器认为它是一个迭代器。)

关于c++ - 使用带参数的 Boost::Thread 时出现编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10969083/

相关文章:

c++ - 是否可以根据任意后验函数定义 Stan 模型?

c++ - 在 C++ 中使用 typedef 声明结构

c++ - 返回一个 2 元组是否比 std::pair 效率低?

c++ - Boost 是什么意思 "header-only libraries"和 "automatic linking"?

c++ - 尝试链接 boost::filesystem 以调试 MSVC11 项目时出现链接器错误

c++ - 为什么这会导致 C2102 : '&' requires l-value

c++ - Excel国际日期格式

c++ - 从 MPL 元函数类创建仿函数

c++ - VS2015 的 Boost nuget 包

c++ - boost::asio::io_service 在 win_mutex 锁中崩溃