gpt4 book ai didi

c++ - "There is no “reference-to-member” type in C++", std::bind 和 boost::bind 在同一条船上

转载 作者:太空狗 更新时间:2023-10-29 21:36:27 26 4
gpt4 key购买 nike

引用标准 (2003) 版本(我认为最近的其他人也这么说)在 8.3.3 的最后,大胆强调是我的:

A pointer to member shall not point to a static member of a class (9.4), a member with reference type, or “cv void.” [Note: see also 5.3 and 5.5. 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 + +. ]

但是我看到了很多

boost::bind(&SomeClass::SomeMemberFunction, this, _1)

还有

std::bind(&SomeClass::SomeMemberFunction, this, std::placeholders::_1)

等工作就像一个魅力,涉及 &SomeClass::SomeMemberFunction,这似乎是对成员函数的引用。

标准是不是简单地说,例如

int (SomeClass::&RefOnSomeMemberFunction) (int) = SomeClass::SomeMemberFunction

不是该语言的有效断言,还是有更多?

最佳答案

您对措辞的理解是正确的。以下格式错误:

int (SomeClass::&RefOnSomeMemberFunction) (int) = SomeClass::SomeMemberFunction;

其实如果看语法规则的话,只有

nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt D1


您对您提到的 boost::bindstd::bind 调用中发生的事情的理解是有缺陷的。在这种情况下,unary &是 addressof 运算符,它产生指向成员(函数)的指针。该指针在您引用的段落中定义。

关于c++ - "There is no “reference-to-member” type in C++", std::bind 和 boost::bind 在同一条船上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40147385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com