What is the principle of information hiding and how does C++ support it. Also does C++ allow me to violate information hiding?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It supports information hiding by allowing
private:andprotected:sections in class declarations.A “supported” way to violate it is via the
friendkeyword, that allows external functions or classes to access theprivateandprotectedmembers of a class (although it’s debatable if that’s actually a “violation”).Also, in a C++ program there’s no runtime enforcing of the visibility rules, so if you manage to get a pointer to an internal field or a function pointer to an internal method nothing stops you from using it (again, this may be intentional – the class itself gave you that pointer – or “abusive” – you have a pointer to the object itself and add some offset to get to an internal member).