TITLE: accessors or public members (Newsgroups: comp.lang.c++.moderated, 5 May 2000) LEPINE: Guy Lepine > inline int GetA () > { > return A; > } > > inline void SetA(int value) > { > A = value; > } > > Would it not be more efficient and faster (in terms of performance) to > just let A be public and cut on the function call overhead? However, I > know this is streching the encapsulation principle. ALEXANDRESCU: "Andrei Alexandrescu" I assume it's about member functions of a class. I just said this in another post. Avoid public data like the plague, even if conceptually you just need a get and a set. Access through functions is much more flexible because you can later on: * change from storing the data in a member variable to computing it on the fly; * validate data upon assignment; * log assignments and trace that data's evolution; * do actions that are triggered by that data's change; * etc. Exposing public data in a class makes your clients dependent not upon a conceptual property of the object, but upon the physical representation of that concept - as a member variable. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com