"Neo" <mo******@hotmail.coma écrit dans le message de news:
%2****************@TK2MSFTNGP04.phx.gbl...
>I was written this code; in VS2k5
<snip>>
A obj;
int temp = *((int *)&obj + 1);
char ch = *((char *)&obj + 8);
cout<< temp<<endl<<ch<<endl;
in Object Orient World we learn Data Encapsulation or Data Hiding for data
security.
In this code, what is the meaning of Data Encapsulation or Data Hiding for
data security?
The aim of data access restriction (protected, private) in OO language is to
protect against Murphy - that is the programmer inadvertently
reading/writing a variable it shouldn't be interested in.
It is not aimed at protecting against Machiavel - that is a hacker who want
to acess data that should be forbidden to it. If you nee that kind of
protection, you probably need cryptography, authentification, access
control, etc...
Anyway, as Vinzenz has said, your "solution" is a hack that depends on
knowledge of the compiler internals working (ie, data padding and
alignement, presence of a v-ptr, data member reorganization, etc...)
Note that this is true in all OO languages, it is not specific to C++.
Arnaud
MVP - VC