Aug 16, 2024

[C++] friend function definition inside a type can be found only through ADL if without forward declaration.

void foo(){
  auto f = &foo;
}


struct Test{

  void foo(){
    auto f = &Test::foo;
  }

  friend void bar(){
    // auto f = &bar; // Use of undeclared identifier 'baz'

    void bar();
    auto f = &bar;
  }

  friend void baz(Test t){
    // Find through ADL
    baz(Test{});
    // auto f = &baz; // Use of undeclared identifier 'baz'
  }

};


int main()
{
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.