Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving a "expression must have pointer to class type" error

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

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

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

I think I've followed the rules of pointer referencing correctly. I still have no idea why this is happening. Could someone help me?

like image 652
hexcode Avatar asked Oct 27 '25 14:10

hexcode


1 Answers

operator-> has higher precedence than operator*, so *m->B is equivalent as *(m->B); while m->B is not valid here.

You should change it to (*m)->B.

like image 94
songyuanyao Avatar answered Oct 29 '25 05:10

songyuanyao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!