Override, Virtual, and Super in C++

When you inherit from a class you have full access to it’s variables and methods. However what do you do when you would like to use one its methods, and then add to it ? Well you would try to override the method with your definition. This can be accomplished using the “Virtual” keyword on the function you want to override on the parent class. And then using the “Override” keyword on the function in the child class. After which you would then use the “Super” keyword to call the implementation of method found in the parent class.

A real world application of this is, when you want to override and add to the “BeginPlay” method.

Override_Super_virtual

Here we see that the TankPlayerController inherits from the APlayerController that inherits from the Actor class. The Actor class holds the initial implementation of the “BeginPlay” method.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s