C ++ reference to class data element

I only recently discovered the existence of a pointer to a class data item, for example:

class Car
{
    public:
    int speed;
};

int main()
{
    int Car::*pSpeed = &Car::speed;
    return 0;
}

Also there is a link to a class data item? If so, which sintax announces them?

+4
source share
1 answer

No, there are no references to class members and there are no values ​​of type "class member". The only thing you have is a pointer to a non-static member of the class (either a data item or a member function).

std::is_member_pointertrait describes this beautifully: an element pointer is a type T U::*, where Uis a class type and Tis an object or function type. (As always, there are no pointers to links.)

+3

All Articles