The point is the same (note: inside class):
void operator - (test*);
...is the same as (note: outside class)...
void operator - (test&, test*);
...and...
friend void operator + (test*, test*);
...is the same as...
void operator + (test*, test*);
...and therefore not allowed.
Try this:
Code:
class test
{
public:
int a;
void operator + (test*);
void operator - (test*);
//friend void operator + (test*, test*);
//friend void operator - (test*, test*);
};
void operator + (test&, test*);
void operator - (test&, test*);
//void operator + (test*, test*);
//void operator - (test*, test*);
int main()
{
test c, d;
(&c - &d); //c is transferred using the this-pointer, and d is the right-hand operand, i.e. test* a
return 0;
}
Remove any comment and it fails to compile.
First two class operators and globals operators are equivalent. Second class operators and globals operators are also equivalent.