#include using namespace std; class Test { private : int data; public : Test() { data = 0; } int getData() { return data; } }; int main() { Test t; int * ptr = ( int *)&t; *ptr = 10; cout << t.getData(); return 0; } |
Out : 10
Note that the above way of accessing private data members is not at all a recommended way of accessing members and should never be used.
No comments:
Post a Comment