关于包含的简单问题 [英] simple question on includes

查看:84
本文介绍了关于包含的简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有可能在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();
...


这篇关于关于包含的简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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