Sorry I thought that’s what you were saying. Though if you’re strictly talking about polymorphism/inheritance then yes. Because
int x = 2.3;
is an implicit cast from
I believe what you’re asking is about upcasting/downcasting. Given the hierarchy:
APawn is an upcast whereas the other way around
ACharacter is a downcast. Upcasts are always safe to do
APawn however the other way round might not be - which is why there’s an if statement in the example as it can and does fail in one instance.
If you have a variable that is of type
APawn*, it may or may not actually be
e.g. With our
ATankPlayerController it will always be controlling an
ATank so it’s a safe assumption to make and personally I wouldn’t bother checking if the cast failed. (This is not true for
ATankAIController later on).