2 years ago

#48326

test-img

Ghasem Ramezani

Why We Couldn't Create Pointer To Friend Functions Defined In A Class?

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:

c++

function-pointers

friend

0 Answers

Your Answer

Accepted video resources