I had made an overloaded "-" operator and it had worked perfectly fine, but since I modified it using pointers and references I'm getting an error, and I think is something wrong with the syntax. I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Invoice
{
//blablabla
}
Invoice& operator-(double *x)
{
this->totalcharge = this->totalcharge - this->totalcharge * (*x * .01);
return *this;
}
main()
{
Invoice *myinvoice = new Invoice();
double percentage;
//percentage is defined, and other stuff.
}
And then I call it like this:
*myinvoice = *myinvoice - percentage;
The error occurs at the minus sign in the line above, and the error is
"No operator "-" matches these operands."
Am I doing something wrong? Any help would be appreciated.
Also I realize the code can be simplified, but this is a lab for my class and I'm supposed to use certain code.
The - operator should not be taking a pointer. Not unless you intend to do some kind of pointer math. Pass by value or by const reference (I would recommend by value in this case).