当我使用
static int CompareFunction(const void* _g1, const void* _g2);
qsort的输入是对的
但使用
int CompareFunction(const void* _g1, const void* _g2);
qsort 的输入错误。错误是:
error: argument of type 'int (<namespace>::<ClassName>::)(const void*, const void*)' does not match '__compar_fn_t {aka int (*)(const void*, const void*)}'
静态如何以这种方式改变行为?我的意思是我所做的只是将类中的函数更改为静态函数,这意味着它现在缺少此指针。我不再做任何改变。
最佳答案
非静态函数只能在对象的实例上调用。 qsort
中没有可调用函数的对象实例(它只有被认为不透明的指针),因此它不能调用成员函数。
关于c++ - 静态函数输出与普通 fn 输出不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445572/