Eliminating the error "expression must have a pointer to the class type"

class testClass { public: int B, C; };

testClass u;
testClass * k = &u;
testClass ** m = &k;

*m->B = 1;//Error appears here

      

I think I followed the pointer rules correctly. I still don't know why this is happening. Can anyone help me?

+3


source to share


1 answer


operator->

has a higher precedence than operator*

, therefore *m->B

equivalent to *(m->B)

; and m->B

is invalid here.



You must change it to (*m)->B

.

+8


source







All Articles