问题描述
我收到此错误:
LNK2019 unresolved external symbol "public: class std::list<class cg::Component *,class std::allocator<class cg::Component *> > __thiscall cg::GameObject::getComponentsInChildren<class cg::Component>(int)" (??$getComponentsInChildren@VComponent@cg@@@GameObject@cg@@QAE?AV?$list@PAVComponent@cg@@V?$allocator@PAVComponent@cg@@@std@@@std@@H@Z) referenced in function "protected: void __thiscall cg::Scene::fixedUpdate(void)" (?fixedUpdate@Scene@cg@@IAEXXZ)
因此找不到在Scene.cpp内部调用的函数getComponentsInChildren。
这是电话:
#include "Scene.h"
namespace cg {
...
void Scene::update() {
for (auto i = this->rootObjects->begin(); i != this->rootObjects->end(); i++) {
std::list<Component*> list = (*i)->getComponentsInChildren<Component>(0); // <--here
for (auto j = list.begin(); j != list.end(); j++)
(*j)->update();
}
}
void Scene::fixedUpdate() {
for (auto i = this->rootObjects->begin(); i != this->rootObjects->end(); i++) {
std::list<Component*> list = (*i)->getComponentsInChildren<Component>(0); // <--here
for (auto j = list.begin(); j != list.end(); j++)
(*j)->fixedUpdate();
}
}
...
}
所以我查看了GameObject.obj的内部,实际上没有包含getComponentInChildren
这是GameObject h + cpp
#include <list>
#include "../Export.h"
#include "../Forwarding.h"
#include "RTTI.h"
#include "Scene.h"
#include "Component.h"
#include "../Components/Transform.h"
namespace cg {
class CGAPI GameObject final {
public:
...
template<typename T>
std::list<T*> getComponentsInChildren(int includeInactive);
...
private:
...
};
}
#include "GameObject.h"
namespace cg {
...
template<typename T>
std::list<T*> GameObject::getComponentsInChildren(int includeInactive) {
if (!RTTI::isComponent<T>())
return nullptr;
std::list<T*> list = getComponents<T>();
for (auto i = this->transform->begin(); i != this->transform->end(); i++) {
if (!includeInactive && !(*i)->getGameObject()->isActiveInHierarchy())
continue;
list.merge((*i)->getGameObject()->getComponentsInChildren<T>());
}
return list;
}
...
}
我真的不明白为什么编译器不将函数输出到obj?我错过了什么吗?还是其他地方出错了?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)