假设有这样一个情况:
// This is all valid in C++11.
struct Foo {
int i = 42;
int& j = i;
};
// Let's take a pointer to the member "j".
auto b = &Foo::j; // Compiler is not happy here
// Note that if I tried to get a pointer to member "i", it would work, as expected.
Foo f;
std::cout << f.*b; // Try using the pointer to member
编译器报错说我不能取成员的地址,因为它是一个引用。确切地说:
语义问题:无法形成指向引用类型“int&”的成员“j”的指针
我知道这样做似乎毫无意义,但我只是想知道为什么不能这样做。
为什么这是不可能的?