Home > Net >  Are pointers to non-static member function "formally" not considered pointers
Are pointers to non-static member function "formally" not considered pointers

Time:05-14

I came across this which states:

Member function pointers are not pointers. Pointers to non-member functions, including static member functions, are pointers.

The above quote seems to suggest that pointers to non-static member function are not pointers.

Similarly, i read here:

A member pointer is a different type category from a ordinary pointer.


My question is that are the above quotes technically(formally according to the standard) correct? I mean we use the term, "pointer" to non-static member function. But if they are not actually pointers then why use the term "pointers" in the first place? My understanding is that it is because although "pointer to member functions" differ in many respect with ordinary pointers they still are similar to ordinary pointers in one respect which is that they point to something(meaning hold addresses).

I also tried:

std::cout<<std::is_pointer_v<void(A::*)()><<std::endl;

which gives 0 confirming that a pointer to non-static member function is not considered a pointer.

CodePudding user response:

The quoted statements in question seems to be validated by the following statements from the standard.

From dcl.mptr#3's note:

[ Note: See also [expr.unary] and [expr.mptr.oper]. The type “pointer to member” is distinct from the type “pointer”, that is, a pointer to member is declared only by the pointer to member declarator syntax, and never by the pointer declarator syntax. There is no “reference-to-member” type in C .  — end note ]

And from basic.compound#3:

...Except for pointers to static members, text referring to “pointers” does not apply to pointers to members...

  • Related