How can I take an address of an overloaded operator defined as a friend in a class body?
I tried the following
struct S {
friend bool operator==(S, S) { return true; }
};
int main() {
bool (*f)(S, S) = &operator==;
}
But gcc gives an error
test.cc: In function ‘int main()’:
test.cc:6:30: error: ‘operator==’ not defined
bool (*f)(S, S) = &operator==;
^
which can be fixed by declaring the operator in the (global) namespace:
bool operator==(S, S);
Is there a way to take the address without redeclaring the operator?