5

我正在查看 cocos2dx c++ 源代码,其中有很多他们使用的地方

class Classname;

例如在 CCNode.h 第 43 行

class CCCamera;

类名是他们正在使用的类的名称,后来我没有看到任何我以前从未见过的引用。

我想知道那是什么意思。

4

1 回答 1

7

This is a forward declaration so that the actual imports occur in the .cpp files instead of the header files. This is a common practice in C++ OOP.

For a good explanation, see this post with a similar question C++ Forward declaration

When you make a forward declaration, you are informing the compiler you intend to use something in advance. The important take aways, as declared in the link above, are that forward declarations break cyclic references and reduce compiler build times.

于 2013-07-27T15:51:28.940 回答