Hello everyone,
I'm currently developing a syntaxic analyser class that needs, at a point of the code, to sort structs holding info about operators. Each operator has a priority, which is user-defined through public member functions of my analyser class. Thus, when sorting, I need my sorting function to order elements based on the priority of the corresponding operator. I'm using the following code to compare elements:
bool parser::op_comp(const op_info& o1, const op_info& o2) {
op_def& op1 = operators[o1.op_char];
op_def& op2 = operators[o2.op_char];
return op1.priority > op2.priority;
}
Note that I had to make this function static, since it's defined inside of a class.
In fact, my compare function compares elements of type op_char
, and I retrieve the operator def from a map which contain elements of type op_def
, which have a field "priority".
The problem I'm facing is that I can't manage to use std::sort(ops.begin(), ops.end(), std::mem_fun_ref(&parser::op_comp))
(where ops is a vector of op_info)
method. I get the following error, which sounds quite logical :
error: invalid use of member `parser::operators' in static member function
Here is my question : how can I force std::sort to use a comp function that makes use of elements from non-static members of the class ? Obviously the function should be non-static, but I can't manage to use it if I don't make it static...
Thanks in advance for your help, CFP.