hexcode
hexcode

Reputation: 403

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?

Upvotes: 4

Views: 3266

Answers (1)

songyuanyao
songyuanyao

Reputation: 172964

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.

Upvotes: 9

Related Questions