我正在尝试使用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)’
如何消除这种歧义?
答案 0 :(得分:3)
需要quicksortInPlace<T>
。