1

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.

Jason
  • 36,170
  • 5
  • 26
  • 60
  • 1
    That's just their colloquialism which *not* quoted from the standard. I don't understand why you are bothering with this. – 康桓瑋 May 09 '22 at 04:49
  • @康桓瑋 Because `std::is_pointer_v` gives false meaning that it is not a pointer but we're still using the term pointer to describe them. – Jason May 09 '22 at 04:50
  • 1
    From [cppreference](https://en.cppreference.com/w/cpp/types/is_pointer): "*Checks whether T is a pointer to object or a pointer to function (but not a pointer to member/member function)*" – 康桓瑋 May 09 '22 at 04:53
  • 1
    I found this in the 1998-09-01 standard #8.3.3(3) [dcl.mptr]: "The type 'pointer to member' is distinct from the type 'pointer'." This is all I have to hand. – user207421 May 09 '22 at 04:55
  • 1
    @user207421 [basic.compound#3](https://timsong-cpp.github.io/cppwp/basic.compound#3): "*Except for pointers to static members, text referring to “pointers” does not apply to pointers to members.*" – 康桓瑋 May 09 '22 at 05:00
  • @康桓瑋 Yep. The wording I gave is also in [dcl.mptr#5](https://timsong-cpp.github.io/cppwp/dcl.mptr#5). – user207421 May 09 '22 at 05:03
  • re your last sentence, no, PMDs/PMFs don't hold addresses. They hold offsets into the class (so pointer to the first member, on gcc/linux to pick an impl, is all-bits-zero, like a null pointer) – Cubbi May 09 '22 at 19:32

1 Answers1

1

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...

Jason
  • 36,170
  • 5
  • 26
  • 60