I'm learning C++ developing a game with Unreal Engine.
I'm using the next code, copied from C++ equivalent of instanceof, to check if an object is an instance of a class:
template<typename Base, typename T>
inline bool instanceof(const T*) {
return std::is_base_of<Base, T>::value;
}
I have the following method signature:
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
Inside the above method I want to check if OtherActor is an instance of class Paddle. Paddle inherits from APawn, which inherits from AActor.
When OtherActor is a APaddle instance, the following code returns false:
if (instanceof<APaddle>(OtherActor))
To check if instanceof is work I have tried the following code, and it works (returns true):
if (instanceof<AActor>(OtherActor))
Why it does not work with a child class (APaddle)?
Aucun commentaire:
Enregistrer un commentaire