What does &Type::variable mean?

时间:2015-07-31 20:20:23

标签: c++

int main()
{
    struct Bob
    {
        int a;
    };

    &Bob::a;
}

What does &Bob::a mean? Bob is a type and not an instance, so what is it taking the address of?

1 个答案:

答案 0 :(得分:2)

It is a pointer to a member of class. According to the standard (N4296, 5.3.1):

The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue or a qualified-id. If the operand is a qualified-id naming a non-static or variant member m of some class C with type T, the result has type “pointer to member of class C of type T” and is a prvalue designating C::m.