I am having troubles with pointers to functions. I am doing something wrong and I just don't see it.
I define a pointer to a member of a class, the pointer is called SelectedCondition, which points to one of 3 class methods, depending on the value of a flag.
The error I get is:
In member function 'bool IntegerCondition::Examine(int)':
../tools//eventselection.h:50: error: invalid use of 'unary *' on pointer to member
class IntegerCondition{
private:
int test;
string rel;
public:
//Constructor
IntegerCondition(){
test=-1;
rel="norelation";
}
//This is the pointer to the member function.
bool (IntegerCondition::*SelectedCondition)(int);
//These are the methods to which SelectedCondition should point.
bool IsItAbove(int num){
return num > test;
}
bool IsItEqual(int num){
return num == test;
}
bool IsItBelow(int num){
return num < test;
}
//Now I selected which method exactly is pointed to by SelectedCondition.
void Set(int testinteger,string relation){
test=testinteger;
rel=relation;
if(rel=="above"){
SelectedCondition=&IntegerCondition::IsItAbove;
}elseif(rel=="equal"){
SelectedCondition=&IntegerCondition::IsItEqual;
}elseif(rel=="below"){
SelectedCondition=&IntegerCondition::IsItBelow;
}else{
SelectedCondition=NULL;
}
}
//This is the line that causes trouble.
//I simply want to evaluate the function to which SelectedCondition points to.
bool Examine(int num){
return (*SelectedCondition)(num);
}
}