gpt4 book ai didi

c++ - 从 boost::thread 调用模板函数时为 "unresolved overloaded function type"

转载 作者:行者123 更新时间:2023-11-30 03:06:50 28 4
gpt4 key购买 nike

我正在尝试使用 boost 的线程工具就地实现快速排序。不幸的是,当我的函数没有重载时,我收到关于“”的错误。代码如下:

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <boost/thread.hpp>

template<typename T>
void quicksortInPlace(std::vector<T> &array,
size_t left,
size_t right,
size_t pivot)
{
size_t storeIndex = left;
// ...
if (left < storeIndex)
{
boost::thread lessThread(quicksortInPlace,
array,
left+0,
storeIndex-1,
storeIndex-1);
lessThread.join();
}
if (right > storeIndex)
{
boost::thread moreThread(quicksortInPlace,
array,
storeIndex+1,
right+0,
storeIndex+1);
moreThread.join();
}

}


int main()
{
std::vector<std::string> stuff;
stuff.push_back("two");
stuff.push_back("one");
size_t left = 0;
size_t right = 1;
size_t pivot = 0;
quicksortInPlace(stuff,left,right,pivot);
return 0;
}

我收到以下编译错误(使用 STLfilt 清理 g++ 输出:gfilt -width:o main.cpp)

BD Software STL Message Decryptor v3.10 for gcc 2/3/4
main.cpp: In function ‘void quicksortInPlace(vector<string> &, size_t, size_t, size_t)’:
main.cpp:56: instantiated from here
main.cpp:36: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t, size_t)’
main.cpp:41: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t, size_t)’

在这里,我使用了“left+0”而不是 left,所以错误不是这种形式

main.cpp:41: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t &, size_t)’

我怎样才能消除这种歧义?

最佳答案

必须是quicksortInPlace<T> .

关于c++ - 从 boost::thread 调用模板函数时为 "unresolved overloaded function type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244420/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com