C++成员指针(Pointer-to-member)操作符

本文链接:http://aztack.wang/post/pointer-to-members-in-cpp.html

 

以前写过一篇关于成员指针的博文,其中提到了MFC是如何使用成员指针的...

 

ISO/IEC 14882:2003 page 85: 5.5 Pointer-to-member operators

The pointer-to-member operators -> and . ...

The binary operator .* binds its second operand, which shall be of the type of "pointer to member of T" (where T is a completely-defined class type) to its first operand, which shall be of class T or of a class of which T is an unambiguous and accessible base class. The result is an object or a function of the type specified by the second operand.

成员指针操作符有两个 -> 和 .

“ .* ”是一个二元操作符,它将第二个参数bind到第一个参数上。其中第二个参数应该是一个指向第一个参数类型(T)的成员指针。而第一个参数应该是类型T的对象或是一个“没有歧义且可访问”的base sub-object。 这个操作符的运算结果是一个对象或函数。(注意:“这个操作符的结果”,而不是最终的结果)

“->*”有类似的定义。

If the dynamic type of the object does not contain the member to which the pointer refers, the behavior is undefined

如果对象不包含指针所指向的内容,那么这个操作符的行为是“未定义的”

If the second operand is the null pointer to member value, the behavior is undefined.

如果第二个操作符是null那么这个操作符的行为是“未定义的”

ISO/IEC 14882:2003 page 137: Pointer to member

The "pointer to member" is distinct from the type "pionter", 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++.

 

posted on 2016-12-20 17:23  zhangyz017  阅读(1453)  评论(0编辑  收藏  举报

导航