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
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.
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.
Variables are properties that hold a value or reference an Object or Actor in the world.
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
.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With