문제

What is the principle of information hiding and how does C++ support it. Also does C++ allow me to violate information hiding?

도움이 되었습니까?

해결책

It supports information hiding by allowing private: and protected: sections in class declarations.

A "supported" way to violate it is via the friend keyword, that allows external functions or classes to access the private and protected members 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).

다른 팁

Is the process whereby the details that show how the programmed program came into function are hidden to avoid access of these details of function to the public users, so it is private and protected act.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top