Member pointer selection

I saw the following binary operator specified in the book p. 191 ,

Point-to-member selection x->*y 

I understand x->y , but not x->*y . Is it a typo or something else?

+4
source share
2 answers

Something else. See C ++ Frequently Asked Questions:

http://www.parashift.com/c++-faq-lite/pointers-to-members.html

+5
source

InformIT Reference Guide: C ++> Pointers for Participants


y is a pointer to a member type inside type *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 pointing at Obj::m // do notice that it not bound to any specific instance of Obj om = 10; std::cout << (p->* y) << std::endl; std::cout << (o .* y) << std::endl; 

Output

 10 10 
+6
source

Source: https://habr.com/ru/post/1386368/


All Articles