What is this kind of syntax called?
Hi,
I am relatively new to C++. I found this piece of code in a project I am working on. Somebody else wrote it. I have never seen this kind of syntax before and I am curious to know more about it:
class A { bool flag; };
class B { A a1, a2, a3; };
/* this is the syntax i haven't seen before */
A B::* arrayname[3] = {&B::a1, &B::a2, &B::a3};
B b;
...
/* and this is how to use it */
if ((b.*arrayname[0]).flag) ...
Thank you.
Re: What is this kind of syntax called?
They're basically pointers which count from the start of a given object rather than globally, effectively allowing you to "choose" a particular field of an object without having to tie the pointer to that *particular* object.