【发布时间】:2013-02-16 02:30:47
【问题描述】:
template<typename T> class testClass{
public:
bool compare(const int& a, const int& b){
T x;
....
}
void sort(){
std::sort( data.begin() ,
data.end() ,
boost::bind<bool>(
&testClass<T>::compare,
this, _1 , _2 ) );
}
std::vector<int> data;
}
我有一个带有非静态成员函数的 template-d 类,用作std::sort 的比较器。比较器取决于typename T 参数。因为它有一个隐含的this 指针,所以我尝试将boost::bind 指针this 指向它。
然而boost::bind<bool>(.......) 和boost::bind(....) 都不会编译。
上面的示例在 MSVC 2008 上失败(因为我在非英语环境中,我不确定英语的确切信息,但可能抱怨任何一个原型都可能使所有必要的参数转换变得可行。)
【问题讨论】:
标签: c++ templates boost stl bind