user2953119
user2953119

Reputation:

Function type to which a pointer to member refers

N3797::8.3.5/6

A function type with a cv-qualifier-seq or a ref-qualifier (including a type named by typedef-name (7.1.3, 14.1)) shall appear only as:

[...]

— the function type to which a pointer to member refers

[...]

Could you get an example? I'm trying the following:

struct A
{
    int foo();
};

int A::* foo() &; //ill-formed.

struct B
{
    int (*bar)() &; //ill-formed
};

Upvotes: 2

Views: 49

Answers (1)

Jan Hudec
Jan Hudec

Reputation: 76246

I've tried to put it through a compiler.

The former,

int A::* foo() &;

is incorrect syntax. To create a pointer to member function, you still need to put in the parenthesis:

int (A::*foo)() &;

and then it is accepted just fine.

The other,

int (*bar)() &;

is accepted by gcc, but my local clang rejects it with

13 col 10 error: pointer to function type cannot have '&' qualifier

and rightfully so. It is a pointer to non-member function and there is nothing to qualify as reference. Gcc apparently just ignores the & instead.

Upvotes: 1

Related Questions