1
struct A
{
  friend void f();
};

void f() {}

We could define a pointer to the f():

using FType = void(*)();
FType ptr_to_f = f;

But if we move the definition of the f() into the A, then we couldn't define any pointer to the f():

struct A
{
  friend void f()
  {
  }
};

using FType = void(*)();
FType ptr_to_f = f; //< error: ‘f’ was not declared in this scope

Why?

From this(Pointer to friend function) CPlusPlus forum:

a friend declaration is not a prototype.

But I don't understand it and couldn't find any documentation about it in:

Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32

0 Answers0