#define private public

本文探讨了C++中使用#define与typedef的区别,通过具体的示例展示了两者不同的应用场景及效果。并讨论了一个有趣的#define用法,该用法能够改变类成员的访问权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今日看到了一句话,#define private public瞬间吓尿了。这define好厉害。好迷惑人啊。所有东西都public了。

http://blog.youkuaiyun.com/wangjieest/article/details/7978382

C++限制访问数据类型的bug啊。一句话就突破了


关于define与typedefi的区别。一个预处理,一个编译器。以下引自stackoverflow。

#define is a preprocessor token: the compiler itself will never see it.
typedef is a compiler token: the preprocessor does not care about it.

You can use one or the other to achieve the same effect, but it's better to use the proper one for your needs

#define MY_TYPE int
typedef int My_Type;

When things get "hairy", using the proper tool makes it right

#define FX_TYPE void (*)(int)
typedef void (*stdfx)(int);

void fx_typ(stdfx fx); /* ok */
void fx_def(FX_TYPE fx); /* error */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值