0

I have an array of structs as you can see below.

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];

I want to sort this array in descending order by the index. So I tried this:

myClass.cpp

bool myClass::sortByIndex(const valueCache &lhs, const valueCache &rhs) { return lhs.index > rhs.index; }

bool myClass::sortArray(
{    
    std::sort(vc, vc + vcSize, sortByIndex);
}

myClass.h

class myClass
{
public:
    bool sortByIndex(const valueCache &lhs, const valueCache &rhs);
}

and i get this error

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&)’

Any ideas how I can fix this?

1
  • 2
    Why not use an STL container? Commented Apr 29, 2014 at 11:40

1 Answer 1

3

Declare sortByIndex static, because you cannot pass non-static member function to std::sort.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.