What is :: * in C ++

I read a basic C ++ tutorial when I came across

::*

in the following code. Can I find out what it is:

class A {
public:
protected:
  int i;
};


class B : public A {
  friend void f(A*, B*);
  void g(A*);
};

void f(A* pa, B* pb) {
//  pa->i = 1;
  pb->i = 2;

//  int A::* point_i = &A::i;
  int A::* point_i2 = &B::i;
}

void B::g(A* pa) {
//  pa->i = 1;
  i = 2;

//  int A::* point_i = &A::i;
  int A::* point_i2 = &B::i;
}

void h(A* pa, B* pb) {
//  pa->i = 1;
//  pb->i = 2;
}

int main() { }

based on my knowledge in C ++, I cannot understand something like

int A::* point_i2

Could you help me?

thank.

+5
source share
2 answers

point_i2is a pointer to an element. This means that it points to a member variable intdeclared in the class A.

+6
source
int A::* point_i2 = &B::i;

After that, when you have a random object Aor B, you can access a member that point_i2points to

B b;
b.*point_i2 = ...;

After the initialization above, point_i2this will change b.i.

ClassName::* , & *: " /", , ,.

+3

All Articles