我有一个结构数组,如下所示。
struct valueCache
{
bool valid;
int startPc;
int index;
f32bit input[12];
f32bit result[12];
};
static const int vcSize = 32;
static valueCache * vc = new valueCache[vcSize];
我想按索引降序对这个数组进行排序。所以我尝试了这个:
我的类.cpp
bool myClass::sortByIndex(const valueCache &lhs, const valueCache &rhs) { return lhs.index > rhs.index; }
bool myClass::sortArray(
{
std::sort(vc, vc + vcSize, sortByIndex);
}
我的类.h
class myClass
{
public:
bool sortByIndex(const valueCache &lhs, const valueCache &rhs);
}
我得到了这个错误
error: argument of type
‘bool (gpu3d::myClass::)(const gpu3d::valueCache&, const gpu3d::valueCache&)’ does not match
‘bool (gpu3d::myClass::*)(const gpu3d::valueCache&, const gpu3d::valueCache&)’
有什么办法可以解决这个问题吗?
最佳答案
声明sortByIndex
static
,因为你不能将非静态成员函数传递给std::sort
。
关于c++如何对结构数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23363588/