I have seen the following binary operator listed on a book pp 191,
Point-to-member selection x->*y
I understand x->y
but not x->*y
. Is this a typo or something else?
y
is a pointer to a member-type inside the type of *x
, see the example below.
struct Obj { int m; };
...
Obj o;
Obj * p = &o;
int Obj::* y = &Obj::m;
// 'y' can point to any int inside Obj, currently it's pointing at Obj::m
// do notice that it's not bound to any specific instance of Obj
o.m = 10;
std::cout << (p->* y) << std::endl;
std::cout << (o .* y) << std::endl;
output
10
10
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