变化当我使用一个静态函数输出与普通FN输出
static int CompareFunction(const void* _g1, const void* _g2);
输入到快速排序是正确
但使用
int CompareFunction(const void* _g1, const void* _g2);
输入到快速排序是错误的。并且错误是: error: argument of type 'int (<namespace>::<ClassName>::)(const void*, const void*)' does not match '__compar_fn_t {aka int (*)(const void*, const void*)}'
静态如何以这种方式更改行为?我的意思是我所做的只是将一个类中的函数改为静态,这意味着它现在缺少这个指针。我没有更多的变化。
如果你的比较器需要访问你的类的部分,请尝试'std :: sort'而不是'qsort'。这会给你更多的灵活性,因为你可以使用函数或lambda函数,而不是只有没有附加参数的普通函数。 – StilesCrisis 2013-03-16 04:32:48