问题
Possible Duplicate:
Accessing private members
Is it possible to access private members of a class?
Is there a good (yes I know this is ugly) way to hack to the private data members of a class?
One brute force approach is to copy the header file and in my copy change private to public. But would there be a better way, say doing
#define private public
or something else?
回答1:
There are lots and lots of ways of doing this - all of them bad. Protection in C++ is there for a purpose, to prevent you from making mistakes. It is not there as a security measure. If you want public access, just make things public!
来源:https://stackoverflow.com/questions/3467261/can-i-trick-access-to-private-c-class-member-variables