虚幻引擎4—类型转换
Unreal Engine 4 -- Typecasting
我目前正在虚幻引擎4中开发我的第一个类。由于广泛使用UScript,我对纯c++中的类型转换如何工作感到有点困惑。更具体地说,是类/对象强制转换。
我目前正在MyCustomGameMode中放置一个开关语句,它调用MyCustomPlayerController的MyCustomPlayerControllerVariable。
我要重写的函数是这个:virtual UClass* GetDefaultPawnClassForController(AController* InController);
目前,我正试图用以下代码行调用变量,我知道这是不正确的,但我不确定为什么:
Cast<MyCustomPlayerController>(InController).MyCustomPlayerControllerVariable
我有兴趣将"InController"转换为MyCustomPlayerController,但Cast<MyCustomPlayerController>(InController)
似乎不起作用,我在这里做错了什么?
cast将返回一个指向播放器控制器的指针,所以你需要使用->来解引用它。
const MyCustomPlayerController* MyController = Cast<MyCustomPlayerController>(InController);
check(MyCustomPlayerController); // asserts that the cast succeeded
const float MyVariable = MyCustomPlayerController->ControllerVariable;
"
强制类型转换时,它总是返回一个指针。因此,在从指针访问变量之前,请确保检查强制转换是否成功。
auto MyPC = Cast<MyCustomPlayerController>(InController);
if(MyPC)
{
MyPC->MyVariable;
}
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++中的双指针类型转换
- 逐位操作的隐式类型转换
- 模板中的类型转换
- 在 C++(和 C)中进行类型转换时明显不一致
- 字符类型转换不兼容
- 将复杂的非基元C++数据类型转换为 Erlang/Elixir 格式,以使用 NIF 导出方法
- C++:用户定义的显式类型转换函数错误
- 将类指针类型转换为键时出错
- 通过引用传递参数时C++类型转换
- 在 C++ 中将一个模板类型的对象类型转换为另一个模板类型
- C++显式类型转换(C 样式强制转换)的强制表示法和static_cast的多种解释
- C++无效的函数类型转换
- 在将派生类指针类型转换为派生类指针后,从基类指针调用派生类函数
- 如何将Windows产品类型转换为名称?
- 通过构造函数方法输出的类到类类型转换是 5500 为什么不是 5555
- 事件系统:使用类型转换或联合进行继承
- 如何在参数中定义隐式类型转换的构造函数?
- 虚幻引擎4—类型转换