我可以欺骗对私有 C++ 的访问吗?类成员变量?

发布于 2024-09-14 09:05:00 字数 563 浏览 6 评论 0原文

可能的重复:
访问私有成员
是否可以访问类的私有成员?< /a>

有没有一种好的方法(是的,我知道这很丑)可以破解类的私有数据成员?

一种强力方法是复制头文件,并在我的副本中将私有更改为公共。但是否有更好的方法,比如做

#define private public

或其他什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2024-09-21 09:05:00

有很多很多方法可以做到这一点——但它们都不好。 C++ 中的保护是有目的的,就是为了防止你犯错误。它不是作为安全措施存在的。如果您想要公开访问,只需公开即可!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文