How to accept the address of an overloaded statement defined as a friend in a body class in C ++

How can I get the address of an overloaded statement defined as a friend in a class cube?

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 an operator in the (global) namespace:

bool operator==(S, S);

Is there a way to accept the address without reusing the operator?

+4
source share
2 answers

, X X, ( X) ,

http://en.cppreference.com/w/cpp/language/friend, .

, , , ADL ( , , , , .).

+5

?

, , .

, 11.3 $6,7 [class.friend] ( )

6 if (9.8), , .

7 . , () , . , , (3.4.1).

+2

Source: https://habr.com/ru/post/1612770/


All Articles