Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is 'class' in 'class DataType* Variable' in Unreal Engine Shooter Game Sample

I recently downloaded the Shooter Game for Unreal 4 Engine and I am just trying to pick apart the c++ but my c++ isn't the best I notice a variable called

class AShooterCharacter* MyPawn; 

Set in the header file for ShooterWeapon.h

I am trying to understand what the class part is.

[Edit] I notice people downed my question so I changed it to one question. I hope people are willing to help rather then degrade my question. Theres no such thing as a dumb question :)... Especially in programming

like image 343
numerical25 Avatar asked Apr 11 '15 16:04

numerical25


People also ask

What is a class in unreal?

A Blueprint Class, often shortened as Blueprint, is an asset that allows content creators to easily add functionality on top of existing gameplay classes. Blueprints are created inside of Unreal Editor visually, instead of by typing code, and saved as assets in a content package.

How do you create a class in Unreal Engine?

Create a new Unreal Engine classIn the Solution Explorer, select a folder where you want to create a new class. Place the caret at a code file open in the editor. In this case, the new class will be created and placed next to the current file.

What is a variable in Unreal Engine?

Variables are properties that hold a value or reference an Object or Actor in the world.


2 Answers

That's so called "forward declaration".

It allows you to specify a pointer to a class/struct name so that you don't have to include the particular header file defining that class/struct.

This feature is particularly viable when breaking circular dependencies between header files.

You can verify that this is the case by checking that AShooterCharacter is not defined in any files included by ShooterWeapon.h.

like image 181
arul Avatar answered Sep 27 '22 21:09

arul


If AShooterCharacter is already in scope, then it probably means basically nothing.

class AShooterCharacter* MyPawn;
// ^ the same as just:
// AShooterCharacter* MyPawn;

In C, when naming structure types, you had to use the struct keyword:

struct Foo
{
   int x, y, z;
};

struct Foo obj;

In C++, you don't need to do that because Foo becomes a nameable type in its own right:

Foo obj;

But you still can write struct Foo if you want to.

The same applies for class, just as a consequence of how the language grammar and semantics are defined.

There are only two times when it makes a difference.

Usage 1: Disambiguation (of sorts)

You can use it to specify that you want to refer to an in-scope type name when it is otherwise being hidden by some other name, e.g.:

class Foo {};

int main()
{
   const int Foo = 3;

   // Foo x;     // invalid because `Foo` is now a variable, not a type
   class Foo x;  // a declaration of a `Foo` called `x`;
}

But if you find yourself "needing" this then, in my opinion, you have bigger problems!

Usage 2: Forward declaration

Otherwise, it is the same as doing this:

class Foo;   // a forward declaration
Foo* x;

Arguably it saves a line of code if you are going to forward declare the type and immediately declare a pointer to an object of that type.

It's not common style, though.

like image 38
Lightness Races in Orbit Avatar answered Sep 27 '22 20:09

Lightness Races in Orbit