cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Class member: When to declare pvt and pu
Class member: When to declare pvt and public
Mar 24, 2015 at 12:34pm UTC
csstudent123
(409)
Please explain to me with least ambiguity when is a class member should be declared public and when private?
Mar 24, 2015 at 12:40pm UTC
tath
(408)
read about basic c++ paradigms - in this case: encapsulation:
http://www.tutorialspoint.com/cplusplus/cpp_data_encapsulation.htm
Mar 24, 2015 at 1:09pm UTC
MiiNiPaa
(8886)
In short:
Data members should be private unless it is just aggregate structure.
Interface should be public (and preferably non-virtual if you are using NVI)
http://isocpp.org/wiki/faq/strange-inheritance#protected-virtuals
http://www.gotw.ca/publications/mill18.htm
Overloadable interface implementation should be private, unless it should be called by derived classes, in this case it should be protected.
Mar 26, 2015 at 5:39pm UTC
csstudent123
(409)
MINIPaaa
what is aggregate structure? you mean aggregation and composition etc?
Mar 26, 2015 at 5:46pm UTC
MiiNiPaa
(8886)
Structure whose only purpose is to group some values together. It has no own behavior, does not do checks, etc. Usually used for data transfer between different applications.
Topic archived. No new replies allowed.