问题描述
我正在尝试定义一个函数以将 UActorComponent 作为参数并使用 FindComponentByClass 根据其 classtype 进行初始化,因此我使用模板如下:
template<class T>
void FindActorComponent(T *aComponent){
aComponent = Getowner()->FindComponentByClasss<T>();
if(aComponent) //doSomething;
else //doOther;
}
然而,我发现pointer(aComponent)传递的对象从函数中出来的是nullptr,虽然不是在里面初始化之后!
所以,我搜索了这种情况的解决方案,发现了这个: Pass pointer by reference,在尝试将参数从 (T *aComonent) 更改为 (T *&aComponent) 后,我发现它起作用了!
谁能给我解释一下这背后的概念,为什么它虽然是通过指针传递的,但它并没有影响传递的对象?
另外,如果我想根据传递的类类型执行一些函数(比如它是 UInputComponent 到 BindAction),我应该怎么做?我尝试使用 GetClass() 但我无法使用它!
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)