boost::为模板类中的非静态成员函数绑定
boost::bind for a non-static member function in a template class
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
指针,我尝试将指针this
指向boost::bind
然而boost::bind<bool>(.......)
和boost::bind(....)
都不会编译。
上面的例子在MSVC 2008上失败了(因为我在一个非英语环境中,我不确定英语中的确切消息,但可能抱怨任何一个原型都会使所有必要的参数转换变得可行。(
好吧,经过一番挖掘。。。问题确实不在于上面的片段。
事实证明,在另一个成员函数中存在类似于(Strange VC++编译错误,C2244(的问题。compare
中调用的一个函数恰好是一个模板函数,未能像上面问题中那样编译。一开始我没有注意到那个错误。
我将部分代码从class.cpp
移到了class.hpp
,现在它可以工作了。
一个愚蠢的微软风投错误,也是我犯的一个愚蠢错误。
相关文章:
- 视觉studo 2019中的漫画和静态/动态绑定
- 在派生类中绑定非静态模板化成员函数
- C++将引用成员绑定到构造函数参数
- 将非静态函数绑定到回调时出现问题
- boost::bind 无法绑定到纯虚拟基类中定义的非静态函数模板成员类型
- | 9 |错误:非静态数据成员'matrix :: row'| 9 |错误:数组绑定不是在']']'令牌|之前的整数常数
- 将静态成员函数绑定为回调
- 如何使用 boost::bind 将静态成员函数绑定到 boost::function
- ROS:将回调函数和对象成员绑定到订阅节点
- 将 QML 中对象的 QAbstractListModel 派生列表模型成员绑定为Q_PROPERTY
- STD ::绑定同类中的静态成员函数
- 对象与静态成员的lua/C++绑定
- 是否有一个模板可以生成类的静态/动态绑定版本
- 将成员函数绑定到局部静态变量
- 将异步操作的处理程序绑定到另一个类的非静态成员
- 具有静态绑定成员函数指针的可变模板的多个专业化
- 将类成员绑定到plain-C函数指针
- 如何在Code::Blocks中将静态库绑定到动态库中
- 编译器何时可以静态地绑定对虚函数的调用?
- 为什么有些语言更喜欢静态方法绑定而不是动态方法绑定