質問

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