本文介绍了奇怪的编译器问题-Visual C ++ Express 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很难解释...而且很长.

我有很多课程,其中两个相关的课程是:对象和AI
在Object类方法中,我使用定义将注释块放置在代码中以用于测试工具.

This is very hard to explain... and long.

I have a lot of classes the two relevant ones in this are: Object and AI
In the Object class methods I used definitions to place comment blocks inside my code for my test harness.

#ifndef TEST
  #define TEST
#endif

#ifdef TEST
  #include <iostream>
  using namespace std;
#endif



然后在我的代码中,我可以使用:



then inside my code i can use:

#ifdef TEST
  cout << "some output" << endl;
#endif



想法是,只要我需要运行测试,就可以轻松地注释/取消注释#define TEST.注释时,编译器将忽略所有输出.
效果很好.

直到我使用相同的想法制作了用于AI的测试工具.我注释掉了对象定义,但仍然出现对象输出.

因此,我认为TEST定义是从AI携带到对象中的,因此我对其进行了更改,使对象定义为TEST_OBJECT,而AI定义为TEST_AI,并且仍然发生对象输出.我注释掉了所有对象输出,并且仍然发生了输出.我删除了整个项目,并使用相同的cpp和h文件创建了一个新项目,但它仍然发生.

因此,简单的问题是:这到底是怎么回事?即使我看到它正在编译,也好像没有在编译对象.

有想法吗?



The idea being that if i can easily comment/uncomment #define TEST whenever i need to run a test. When it is commented all the outputs will be ignored by the compiler.
It worked great.

Until I made the test harness for AI using the same idea. I commented out the Object definition but the Object outputs still occurred.

So I figured the TEST definition was being carried from AI into object so I changed it so the object definition was TEST_OBJECT and the AI definition was TEST_AI and the Object output still occurred. I commented out all the Object outputs and the output still occurred. I deleted the entire project and created a new project using same cpp and h files and it still occurred.

So the simple question is: why the hell is this happening?! It''s like Object is not being compiled even though I can see it compiling.

Thoughts?

推荐答案

#ifndef TEST
#define TEST
#endif


在Visual Studio的相应属性表中,在项目级别定义预处理程序常量"TEST".我建议在一个中央属性表中对其进行定义,您将在每个项目中引用该属性表.


Define the preprocessor constant "TEST" at project level, in the resepective property sheets of Visual studio. I recommend to define it in a central property sheet which you will reference from each project.


这篇关于奇怪的编译器问题-Visual C ++ Express 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:27