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
accessing private members from header fi
accessing private members from header file
Dec 27, 2013 at 9:12pm UTC
amulyav
(1)
i have seen many c++ programs, where the private members from a header file are accessed in the source file. why is happening? As to my knowledge a private member cannot be accessed until it is friend function or member.
Dec 27, 2013 at 9:38pm UTC
ne555
(10692)
> until it is friend function or member.
¿is it?
Dec 27, 2013 at 9:43pm UTC
Duthomhas
(13148)
The header file doesn't hide the stuff in the object. All that stuff must be known to the compiler and all units that use the object.
However, by making stuff private you are saying "don't touch" to everything other than that object's methods and friends.
If you really want to hide all implementation details from anyone who doesn't have your full source code, check out the PIMPL idiom.
Hope this helps.
Topic archived. No new replies allowed.