Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cannot access member data via ' *this '

Say if I have a class named cube which refers to a 3D cube, and it has a private member data called _height. Within the class I tried to use

this->_height

and it works. (I know ‘_height’ along is enough. I just want to try more about ‘this’ pointer).
However when I use

*this._height

inside the class. It reports error. ‘this’ is a pointer points to the object in use thus ‘pointer->member’ method is valid. Meanwhile ‘*this’ should be the object itself, but why it forbids me to use the ‘.’ (dot) method?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Due to the precedence of the . over the * you need to put brackets around to make sure you get what you want:

(*this)._height
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading