Question regarding illegal operand

Part of my program I am working on keeps telling me that I am using an illegal operand. Yes it is part of my homework, but no I am not asking you to do it for me. I don't understand why it says that the double is an illegal operand.

class employee
{

public:
string name;
int hours;
double rate;
double otRate()
{
return rate*0.5;
}
double total1()
{
return hours*rate;
}
double otPay()
{
return (&employee::otRate)*(hours-40);//this is the error line.
}
};
otRate is a function. You need to call the function like this otRate()
Out of interest, what are you trying to do with this line?

return (&employee::otRate)*(hours-40);//this is the error line.

the error is not the double is an illegal operand, it's (with VC++)

error C2296: '*' : illegal, left operand has type 'double (__thiscall employee::* )(void)'

employee::otRate is a member function of employee with has no params and returns a double.

Did you mean

1
2
3
4
double otPay()
{
    return otRate()*(hours-40);
}


or were you trying to use a member function pointer?

Andy
Last edited on
I would rather not use the pointer.

The line should calculate the amount of money that a worker is going to earn just for the overtime he or she works. I have it working now. Thank you very much for pointing me in the right direction.
Topic archived. No new replies allowed.