本文介绍了有没有办法在每个源文件中自动复制#define的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以下内容出现在我的 Visual C++ 2005 解决方案的每个源文件中:

I'd like the following to appear in every source file in my Visual C++ 2005 solution:

  #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
  #define new DEBUG_NEW

有没有办法在不手动复制的情况下做到这一点?编译器选项?

Is there a way of doing this without manually copying it in? Compiler option?

推荐答案

命令行选项 /D 可用于定义预处理器符号.不过,我不知道它是否也可以用于定义带参数的宏,但测试它应该很容易.

The command line option /D can be used to define preprocessor symbols. I don't know, though, whether it can also be used to define macros with arguments, but it should be an easy matter to test that.

如果失败,/FI 选项(强制包含")应该允许你做你想做的事.引用 MSDN 文档:

此选项与在每个源文件 [...] 的第一行的 #include 指令中用双引号指定文件具有相同的效果.

然后您可以将您的 #define 放入该强制包含文件中.

You can then put your #defines in that forced include file.

这篇关于有没有办法在每个源文件中自动复制#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:23
查看更多