I have a class Foo
class Foo {
...
};
for which I have overloaded the subtraction operator declared as
int operator-(const Foo&, const Foo&);
When I use this:
Foo a, b;
...
int n = a - b;
the compiler looks for the implementation of
int operator-(Foo, const Foo&);
and does not use my operator. If I modify the code to be
Foo a, b;
...
int n = (const Foo&)(a) - (const Foo&)(b);
everything is fine.
I do not understand why I need to cast a and b.
class Foo {
...
};
for which I have overloaded the subtraction operator declared as
int operator-(const Foo&, const Foo&);
When I use this:
Foo a, b;
...
int n = a - b;
the compiler looks for the implementation of
int operator-(Foo, const Foo&);
and does not use my operator. If I modify the code to be
Foo a, b;
...
int n = (const Foo&)(a) - (const Foo&)(b);
everything is fine.
I do not understand why I need to cast a and b.
Comment