更新时间:2023-02-14 23:02:24
简单的答案是,C ++没有定义您尝试的转换,因此程序格式错误.
The simple answer, is that C++ does not define the conversion you are attempting and thus your program is ill formed.
考虑标准转换(C ++11§4/1):
Consider standard conversions (C++11§4/1):
标准转换是具有内置含义的隐式转换.第4章列举了此类转换的全部内容.
Standard conversions are implicit conversions with built-in meaning. Clause 4 enumerates the full set of such conversions.
由于您没有执行任何强制转换,也没有定义任何自定义转换,因此实际上您正在执行这种标准转换.在没有列举所有可能的此类转换的情况下,您的示例明确涉及了两个: pointer 转换和 pointer to member 转换.请注意,C ++并不将指向成员类型的指针视为指针类型的子集.
Since you are not performing any cast, nor do you have any custom conversions defined, you are indeed performing such a standard conversion. Without enumerating all possible such conversions, two are of explicit interest for your example: pointer conversions and pointer to member conversions. Note that C++ does not consider pointer to member types to be a subset of pointer types.
指向成员转换的指针在C ++11§4.11中定义,并且正好包含两个转换:
Pointer to member conversions are defined in C++11§4.11 and consist of exactly two conversions:
指向cv T类型的B的成员的指针",其中B是类类型,可以转换为指向cv T类型的D的成员的指针",其中D是派生类[...] of B
void
的指针(4.10/2),这允许将任何指针类型转换为指向 void
的指针.void
(4.10/2) which allows the conversion of any pointer type to pointer to void
.其中D是类类型的[[cv D的指针],可以转换为[cv B的指针],其中B是基类[...]D的]