预处理器指令“使用”
根据我之前学习 C 的知识,我知道像 #include
、 #define
这样的预处理器指令不是一个语句,这就是为什么顾名思义,这是程序编译之前的过程,因此我们不需要在其末尾附加;
。
在 C++ 中,它向我引入了一个新指令 using
,但为什么该指令附加一个分号?我认为这就像我之前学到的指令一样,它不是一个声明?
From my previous knowledge in learning C, I know that preprocessor directive like #include
, #define
is ain't a statement that's why as the name implies , it is process before the program is compiled , therefore there's no need for us to append a ;
at the end of it.
In C++, it introduces me a new directive that is using
, but why this directive append a semicolon? I thought it's just like the previous directive I learn where it's not a statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
using
不是预处理器指令。它由编译器本身查看和分析。事实上,您通常不会在
#define
宏的末尾放置;
,因为它们被预处理器处理为“简单”文本替换,例如:是一个编译器错误,因为编译器会看到:
using
is not a preprocessor directive. It is seen and analyzed by the compiler proper.The fact that you often don't put a
;
at the end of#define
macros is because they are processed as "simple" text replacement by the preprocessor, e.g:would be a compiler error since the compiler would see:
using
可以被认为是一个声明,例如typedef
就是这样。你可以要求编译器输出预处理的结果,例如使用
g++ -C -E
,但没有简单的方法要求它输出using
的效果using
can be thought as being a declaration, like e.g.typedef
is.And you can ask the compiler to output the result of preprocessing, e.g. with
g++ -C -E
but there is no simple way to ask it to output the effects ofusing