#include任何地方 [英] #include anywhere

查看:202
本文介绍了#include任何地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< file> 只用于标题,或者只是一个机械的在这里注入这个代码,可以在代码?

Is the #include <file> meant to be used for headers only or is it simply a mechanical "inject this code here" that can be used anywhere in the code?

如果我在cpp函数中使用它来从单个源注入代码,该怎么办?

What if I use it in the middle of a cpp function to just "inject" code from a single source? will this work or will compilers scream about this?

推荐答案

一个机械注入这里的代码设备。如果您愿意,可以包含一个包含歌德浮士德的文本文件。你可以把它放在任何地方,即使在一个函数的中间(当然, #include 需要一个新行!)。

It is a mechanical inject the code here device. You can include a text file containing Goethe's Faust if you wish to. You can put it anywhere, even in the middle of a function (of course, #include needs a fresh line!).

但是,对于头文件只使用 #include 是很强大的约定。可能有些原因我不会反对,例如拉入机器生成的代码或将所有翻译单元合并到一个文件中。

However, it's strong convention to only use #include for header files. There may be reasons where I wouldn't object on it, for example pulling in machine-generated code or merging all translation units in a single file.

这篇关于#include任何地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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