c++ - #include 混淆和类

标签 c++ class include

我一直在使用 Allegro API 和 C++ 制作几款游戏。我也一直将我所有的类(class)放在 1 个大的 main.cpp 文件中。我多次尝试制作 .h 和 .cpp 文件,但我的大问题是我在正确的位置使用#including 遇到了麻烦。例如,我希望我所有的类都可以访问 allegro 库,而无需到处都使用#including allegro.h。有人可以解释如何正确#include 东西。在 .Net 中,一切似乎都在一起,但在 C++ 中,一件事在包含之前不能使用。还有一种方法可以在我的整个程序中全局包含一些东西吗? 谢谢

最佳答案

I want all my classes to access the allegro library without #including allegro.h everywhere.

为什么?这就是您在 C++ 领域中的做法。

Could someone please explain how to correctly #include things. In .Net, everything seems to come together, but in c++ one thing cannot be used before it is included

从概念上讲,在 .NET 中并没有太大区别。您仍然必须将“使用”放在顶部。不同之处在于,在 .NET 中,如果需要,您也可以每次都这样写:

void Foo( System.Drawing.Drawing2D.BitmapData bData ) { }

关于c++ - #include 混淆和类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2197024/

相关文章:

java - 如何打破父类(super class)构造函数链?

ant - 在 Ant 构建任务中包含外部资源

php - fatal error : Call to a member function prepare() on a non-object with PDO

c++ - 在 C++ 中访问 std::string 时出现 std::out_of_range 错误

c++ - 我可以在这里使用 Curiously Recurring Template Pattern (C++) 吗?

c++ - 如何为 python 编译 C/C++ 函数

c++设计模式问题。单一接口(interface)多种实现?

Java - 检查对象数组是否包含特定字符串

node.js - 从包含的 eval 脚本访问 Nodejs main 的局部变量上下文

java - 创建注释类实例的数组列表