首页 > 解决方案 > 没有正文的 class 关键字有什么用?

问题描述

我不明白Unreal C++ 中的“类”是什么意思

class USpringComponent* BoomArt;
class UCameraComponent* Camera;

据我所知,班级必须有一个身体,但没有这样的事情。为什么要写一个?这个关键词的一般逻辑是什么?

我已经习惯了看到这个:

class MyClass
{
   // body...
}

为什么要在 Unreal C++ 中提前写好 class 关键字?再次:

**class** USpringComponent* BoomArt;

标签: c++classunreal-engine4

解决方案


您可以转发声明一个类型而无需完全定义它。关于如何使用前向 ddeclared tpye 有一些限制,但定义指针是一个有效的用例。

线

class USpringComponent* BoomArt;

相当于

class USpringComponent;    // Forward declaration of the class
USpringComponent* BoomArt; // Define a pointer to an object of the class.

相关:我什么时候可以使用前向声明?


推荐阅读