此宏有什么问题? [英] What is wrong with this Macro?

查看:76
本文介绍了此宏有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define mySynthesize(op) @synthesize op = _op;

所以不要输入

@synthesize someVar=_someVar;
@synthesize otherVar=_otherVar;

我可以做

mySynthesize (someVar);

好吧,虽然没有用.我做错了什么?

Well, it doesn't work though. What did I do wrong?

推荐答案

op加上下划线前缀时,预处理器会将其视为其他令牌,因此不会被替换.您需要使用##将下划线连接到前面,以便首先进行替换.

When you prefix the op with an underscore, the preprocessor treats it as a different token, so it doesn't get replaced. You need to use ## to concatenate the underscore to the front so that the replacement occurs first.

#define mySynthesize(op) @synthesize op = _ ## op

这篇关于此宏有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆