相关疑难解决方法(0)

使用成员函数作为比较器排序问题

试图编译以下代码我得到这个编译错误,我该怎么办?


ISO C++禁止获取非限定或带括号的非静态成员函数的地址,以形成指向成员函数的指针.

class MyClass {
   int * arr;
   // other member variables
   MyClass() { arr = new int[someSize]; }

   doCompare( const int & i1, const int & i2 ) { // use some member variables } 

   doSort() { std::sort(arr,arr+someSize, &doCompare); }

}; 
Run Code Online (Sandbox Code Playgroud)

c++ sorting stl compiler-errors

30
推荐指数
4
解决办法
3万
查看次数

标签 统计

c++ ×1

compiler-errors ×1

sorting ×1

stl ×1