C++ Pointer Syntax Question

Hi,

I have doing some starting courses for UE4 Development, and I had a question relating to C++ usage in UE4.

I’m doing a tutorial to create a basic position reporter.

Below is the peek definition of GetOwner() .




FORCEINLINE_DEBUGGABLE class AActor* UActorComponent::GetOwner() const
{
#if WITH_EDITOR
	// During undo/redo the cached owner is unreliable so just used GetTypedOuter
	if (bCanUseCachedOwner)
	{
		checkSlow(OwnerPrivate == GetTypedOuter<AActor>()); // verify cached value is correct
		return OwnerPrivate;
	}
	else
	{
		return GetTypedOuter<AActor>();
	}



Could someone walk me through what the following line is doing exactly?

Is: class AActor* grabbing the memory address of AActor? Or is it creating a pointer?
I know the basics of pointers (pointer POINTS to memory address of something, can be dereferenced…) Just having trouble wrapping my mind around this section.




FORCEINLINE_DEBUGGABLE class AActor* UActorComponent::GetOwner() const



I’m seeing alot of this in various parts of UE4 source code, such as in UObjectBase, so I trying to figure out this all out.




UObjectBase::UObjectBase(**UClass* InClass**, EObjectFlags InFlags, EInternalObjectFlags InInternalFlags, **UObject *InOuter**, FName InName)
:	ObjectFlags			(InFlags)
,	InternalIndex		(INDEX_NONE)
,	ClassPrivate		(InClass)
,	OuterPrivate		(InOuter)
{
	check(ClassPrivate);
	// Add to global table.
	AddObject(InName, InInternalFlags);
}



Thanks for reading.

Let us start with the CONST after the function. All the const does it makes the function unable to make any edits to the class of which it is a part. It can only make and update local variables and parameters.
The FORCEINILE_DEBUGGABLE does several things. First, it forces all calls to it to be inlined into where it is called. This is just a trick to speed up execution time. I dont know what the DEBUGGABLE part does, but maybe it only does this in release builds to allow for debugging in debug mode?
The CLASS keyword in this context is the only one that I have no idea about. It is almost as if it is an access specifier, but I cant think of a usecase that is not already covered by PRIVATE and PROTECTED.

The rest is straight forward. It returns an AActor pointer: AActor*, then it specifies that it is part of the UActorComponent: UActorComponent::, before finally specifying which header function it should be linked to: GetOwner().

I hope this helped you a little. I was not able to explain everything, but at least it is a start. GL.

It’s an inline forward declaration of AActor, so the component header doesn’t have to include the actor header.

Wait, an inline class forward declaration? With a function after it? I would understand


class AActor;

But not written like that. Is that standard C++ or UE4 C++?

Yeah, you can inline forward declarations. So instead of this


class AActor;
AActor* blah;

You can simply write


class AActor* blah;

It can also be done inside method declarations and everything, random example from the engine:


virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override;