[Tutor] Slightly OT: public/private class members

pcarey@lexmark.com pcarey@lexmark.com
Fri Feb 14 08:17:12 2003


Hello.
I'm only in my second C++ class at the local university, but I've been
using Python for a while. We are just now beginning to create C++ programs
that use classes. My prof says "99% of all data members of a class should
be private" in a quasi-brainwashed kind of way. My question is thus:
when/why would data members/methods need to be private? I know python has
adopted a "we're all consenting adults" point of view (cannot remember
where I read that). I rather like that point of view, and dislike creating
all these "get & set" methods to fetch/set data members from an object.

So, what's the need/use for private members?

Sorry if this is OT, but I've not really heard any good arguments that
support "privatizing" all data members...but then again, I'm pretty much a
CS rookie.

TIA,

Pete