How to make such a cast in c++

Just note that Cast<> is a UE4 thing, not standard C++ casting method. The big difference is it checks in UE4 reflection system that object you try to cast is actually related to class you try to cast to. If it fails it returns nullptr (you don’t need to do IsValid at that point to check, just normal null pointer check is enough and faster).