[LC++]Is there a place for public data members?
Mark Phillips
mark at austrics.com.au
Mon Nov 5 19:14:04 UTC 2001
Hi,
Instead of doing
class myClassTy {
public:
int myInt;
};
another approach is to do:
class myClassTy {
private:
int myIntVt;
public:
int myInt() const {return myIntVt;}
int& myInt() {return myIntVt;}
};
The impression I have gained is that people think the latter is
better because it allows myClassTy to be implemented differently
later on if I so desire, without it affecting code that uses myClassTy.
But are there cases where it is overkill? Should I only take the
latter approach for more complicated kinds of classes, or is it
wise to _always_ take the latter approach? If the former approach
is sometimes appropriate, is there any rule-of-thumb for determining
which approach to use in a given situation?
Of course this is all probably a matter of opinion... but I'm interested
in hearing what people's opinions are.
Thanks,
Mark.
More information about the tuxCPProgramming
mailing list