Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ qsort C+;中非静态成员函数的使用无效+;_C++ - Fatal编程技术网

C++ qsort C+;中非静态成员函数的使用无效+;

C++ qsort C+;中非静态成员函数的使用无效+;,c++,C++,下面是我在SuffixArray类中的函数: int pstrcmp(const void *a, const void *b) { return strcmp((const char *)*(char **)a, (const char *)*(char **)b); } 我在qsort中使用了这个比较函数: qsort(ap, len1+len2, sizeof(char *),pstrcmp); 哪个ap是后缀的指针数组 当我编译它时,有一个错误: 非静态成员函数的使用无效 我用no

下面是我在SuffixArray类中的函数:

int pstrcmp(const void *a, const void *b) {

return strcmp((const char *)*(char **)a, (const char *)*(char **)b);
}
我在qsort中使用了这个比较函数:

qsort(ap, len1+len2, sizeof(char *),pstrcmp);
哪个ap是后缀的指针数组

当我编译它时,有一个错误: 非静态成员函数的使用无效

我用notepad++来编译它,它提供了

 error: cannot convert 'SuffixArray::pstrcmp' from type 'int (SuffixArray::)(const void*, const void*)' to type 'int (*)(const void*, const void*)'
 qsort(ap, len1+len2, sizeof(char *),pstrcmp);

<> P>有人能帮助我吗?

< P> C++中,您需要将一个独立的函数或一个静态成员函数(与非静态成员函数相对)传递给<代码> qStase,因为非静态成员函数的调用约定需要一个实例通过。 您有两种解决此问题的方法:

  • pstrcmp
    的声明移出
    subfixarray
    类,或
  • 在类中声明
    pstrcmp
    静态

你用C++标签来标记这个。如果这是C++,那么避免C风格的转换,使用C++的强制转换来让你的意图更加清晰。我不喜欢你用不必要的强制转换来表达你的论点。“DAO用C来标记它,我重新标记了C++,因为它显然不是C问题。