关于包含的简单问题

问题描述:

我听说有可能在C ++项目中指出

a头文件,你想要包含在

整个项目中(即,所有课程都可以使用它)。

我可以把这样的包括在内吗?谢谢。



ps。如果我在一个类中声明一个枚举,我怎么能在另一个类中使用它?

Hi, I''ve heard it is possible to indicate in a C++ project
a header file which you want to be included throughout the
whole project (i.e., all classes can use it). where
can I put such an include? Thanks.

ps. If I declare an enum in one class, how can I use it in a different?

我认为你正在考虑预编译头的概念。您有一个单独的头文件(在mfc中它是stdafx.h),您可以在其中添加包含(通常是经常需要的包含),然后您只需将此头文件包含在所有其他文件中。为了安全起见,您可以在项目设置中配置自动包含此文件。预编译头的一大优点是编译项目的速度要快得多,因为自上次编译以来没有改变的文件不会被编译。



As对于枚举,只要你声明它是公开的,你可以按类访问它范围:



I think you are reffering to the concept of precompiled headers. You have one single header file (in mfc it''s stdafx.h) where you add the includes (mostly the ones that are often needed) and afterwards you are just include this header file in all other files. To be on the safe side, you can configure in your project settings, that this file is included automatically. A big advantage of precompile headers is the compilation of your project is much faster because files that haven''t changed since last compile won''t be compiled.

As for the enums, as long as you declare it public you can access it by class Scope:

class EnumWrapper
{
public:
  enum Colors
  {
     Red,
     Blue
  }
}


...
if(EnumWrapper::Red) doStuff();
...