Some novice questions about C ++.

Hi, I’m starting to know this world through the book “Learning C ++ by creating games with UE4”. Little by little I am learning things but when I see UE4 code I get lost in some points.

For example:

What is the parameter of the “SetupPlayerInputComponent” function? I had never seen it expressed that way. Is it a “UInputComponent” class? What does the asterisk do? And “PlayerInputComponent”? It reminds me of the pointers, but it’s different.

bb508772bb8df7defbe50b9312df77ab.png

I have read something about “Super”, but I can not find references in the documentation, only references to the “super” of another programming language. Can you show me any reference?

They are some doubts that I have now, I have many more, but I do not remember them.
Thank you.

“class” is an optional descriptor, it would work fine without it (usually). There’s a good answer here about it.


UInputComponent* PlayerInputComponent

UInputComponent is the class name. The asterisk shows that it’s a pointer to an instance of that class. PlayerInputComponent is just the name of the variable.

“virtual” and “override” mean that the parent class also has a SetupPlayerInputComponent function with the same signature (and also virtual). When a function is virtual, any call to the function will search down the class hierarchy to find the lowest definition of it. So instead of using the parent’s SetupPlayerInputComponent, it’ll use this one. This is what lets us override functions in children.

“Super” generally means the same in every language. It’s a reference to the parent, so in this case it’s calling the parent’s implementation of SetupPlayerInputComponent.

So those are the technical answers, but it’s good to get a sense for what this pattern is since it’s used a lot. Whoever programmed this wanted a SetupPlayerInputComponent function that did what the parent’s did, but also added some more stuff. To accomplish this, they overrode the function (which they could do because it was virtual), and called the parent’s implementation (through Super) and can now add their own code.

Thank you so much.