Suppose I have a class Foo
, with a private variable bar_
containing some state for Foo
. If necessary, I may write public get/set metho
If your compiler does any inlining at all, it will be able to inline get and set methods defined and used within a given class. const
has no bearing on this, and the inline
directive doesn't make much difference either.
I generally prefer to use my get()
and set()
methods even from within the class definition, when I can. You get all the same benefits that you get by using them outside the class definition, and there is no speed penalty.