0

for the following code:

class A {
    friend void fun(){};
};

int main() {
    fun();
}

I know that it is illegal since fun cannot be find with normal lookup rules. My question is: why C++ choose this design and doesn't let fun to be find?

Thanks!

Wei Li
  • 1,847
  • 2
  • 10
  • 10
  • @sweenish - It's not private. It's not visible to name lookup at all. A private function would still be found (albeit with a slap on the wrist for trying to touch it). – StoryTeller - Unslander Monica Jul 04 '21 at 14:31
  • Good points. I hastily commented, as I know I've implemented friend functions in a class declaration before, but there was obviously something different going on with my implementations versus this one. – sweenish Jul 04 '21 at 14:34
  • That's what's called a **hidden friend**, and it can be hard to get to if it does not have the class as a parameter, which allows for ADL. – Eljay Jul 04 '21 at 14:34
  • This is the difference my implementations had. – sweenish Jul 04 '21 at 14:35

0 Answers0