Calling this->get/this->set methods versus directly accesing member variables in C++
<p>Suppose I have a class <code>Foo</code>, with a private variable <code>bar_</code> containing some state for <code>Foo</code>. If necessary, I may write public get/set methods for <code>bar_</code>. Naturally, I avoid this as much as possible to maintain encapsulation.</p>

<p>Assuming I have these get/set methods, whenever I have to access or modify <code>bar_</code> within a method belonging to <code>Foo</code>, I usually do it directly to <code>bar_</code>, instead of using the get/set methods, which I use for accessing <code>bar_</code> from outside the class. I have no justification other than concerns regarding the speed of directly accessing the variable versus calling the methods, but I suspect that if the get/set methods are defined inline (which they are) it shouldn't make a difference. Does it make a difference? Does <code>const</code>ness play a role in this?</p>

<p>So far I haven't had any problems with this, but I have a lingering feeling I am Doing It Wrong. Are there any compelling arguments for not doing it? Any guidelines regarding this?</p>
