I've only recently discovered the existance of pointer to class data member, for example:
class Car
{
public:
int speed;
};
int main()
{
int Car::*pSpeed = &Car::speed;
return 0;
}
Do reference to class data member also exist? If so, which is the sintax to declare them?
No, there are no references to class members, nor are there values of type "class member". The only thing you can have is a pointer to a non-static class member (to either a data member or a member function).
The std::is_member_pointer
trait summarizes this nicely: a pointer-to-member is a type T U::*
, where U
is a class type and T
is an object or function type. (As always, there are no pointers to references.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With