c++ qsort中非静态成员函数的无效使用
invalid use of non-static member function in qsort 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是后缀
的指针数组当我编译它时,有一个错误:非静态成员函数
的无效使用我用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);
有人能帮我吗? 在c++中,您需要向qsort
传递一个独立函数或静态成员函数(与非静态成员函数相反),因为非静态成员函数的调用约定需要传递一个实例。
这个问题有两个解决方案:
- 将
pstrcmp
的声明移出SuffixArray
类,或者 - 在类中声明
pstrcmp
静态
相关文章:
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 在这个函数中是有缺陷的,因为取消引用 null 是无效的,所以我想更改代码
- 在 Microsoft Access SQL 中调用自定义 DLL 函数时传递的内存地址无效
- C++无效的函数类型转换
- C++无效使用非静态成员函数?
- 模板和无效函数调用C++
- 控件到达非无效函数的末尾[-Wreturn类型]
- 获取控制权到达非无效函数警告的末尾,尽管我在 th 函数中有返回语句
- C++ 指针无效函数问题
- 为什么我总是得到 - 警告:控制达到非无效函数的末尾 [-Wreturn-type]
- 在无效函数中使用退出来纠正错误是否是一种好的做法
- 在C++ 通过按键进入和退出无效函数调用
- 指向指向无效函数参数的指针
- Xcode - 控制到达非无效函数运算符错误的末尾
- C++:对无效函数的未定义引用
- 二叉树无效函数
- 控件到达非无效函数的末尾
- 控件到达非无效函数的末尾
- 控制可能会到达非无效函数 xcode 的末尾