是非静态成员函数的指示。不被视为指针

发布于 2025-01-27 08:53:38 字数 701 浏览 2 评论 0原文

我遇到 this

成员函数指针不是指针。指示非会员功能,包括静态成员函数,是指针。

上面的报价似乎表明指向非静态成员功能不是指针。

同样,我阅读在这里

成员指针是与普通指针不同类型的类别。


我的问题是在技术上是上述引号(按标准形式上)正确吗?我的意思是我们将术语“指针”用于非静态成员函数。但是,如果它们实际上不是指针,那么为什么首先使用“指针”一词呢?我的理解是因为尽管“指向成员函数的指针”在许多方面与普通指针有所不同,但它们在一个方面仍然与普通指针相似,即它们指向某种东西(意思是持有地址)。

我还尝试了:

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

它给出0确认指向非静态成员函数的指针不被视为指针。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩于岁月 2025-02-03 08:53:38

所讨论的报价似乎通过标准的以下语句验证。

来自 dcl.mptr#3的注释

[注意:另请参见[Expr.unary]和[Expr.mptr.oper]。 类型的“指向成员指针”与“指针”类型不同,也就是说,仅由指向成员声明器语法的指针来声明,而从未由指针Dectrator语法来声明。 C ++中没有“参考成员”类型。 - 终注]

basic.compound#3

...除了指向静态成员的指针外,指“指针”的文本不适用于成员的指针...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文