ActionRPG Sample - I don't underestand some c++ code

I’m learning GAS and decided to see how it works on other projects. Especially on ActionRPG sample from Epic’s that available on the Marketplace for free.
There is class - RPGCharacterBase.h
And in it:

My knowledge of c++ is very limited. Last time i used this language was in the University in 2011. A lot of time passed since then. And i can’t underestand this construction:

class URPGGameplayAbility;
class UGameplayEffect;

How is it suppose to work? Why is it there? How … is actually this named in c++? How is this even possible? I never seen anything like this before. Please, explain it to me.

And here is another code sample that i never seen in c++:

Is it foreach? But there is foreach in STL and it looks differently:

array<int, len> M = {1,2,3,4,5};

if it’s not foreach then… what is it? How it works? How to get index out of it? And Why is it const?
For each GameplayAbilitySpec take non modifiable refrence, name it Spec and proceed, is it correct?

Hi, I’m still learning C++ myself but I will try answer your questions.

These are forward declarations, instead of including the headers of these classes in the header of this class, you write this. Then in the CPP file at the top, you include the header there. This is to reduce compile times. See here:

This is a range-based for loop. Here it iterates over the AbilitySystemComponent->GetActiveAbilities. Over each iteration the element would be Spec.
The const is to tell the compiler that Spec (the element) will not change.


Thanks a lot!

And here is another question, if you don’t mind.

This is the method and it has
bool ReplicateObject(class UActorChannel *Channel, class FOutData *Out) override;
it has two class … parameters in the arguments. I never seen class to be defined this way eather.
I underestand if that was types as arguments. But there is class Type *pointer and …
Is it again forward declaration? It looks like so, but just asking to be sure.

And here is another construction:

class A{
	class BCD* tmp;

what … tmp variable will be in this case? will it have BCD class pointer? Is it again forward declaration?

Yes, that is correct. The difference is scope. The first version that you asked about is done at file scope, so it makes the type visible for the entire header (and anyone that includes that header). The second one is only valid for the single variable that is being declared. With the first version, it’s the only declaration required in the header. With the second, you would have to repeat the ‘class’ keyword for every function parameter of that type.