0

I get this error:

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)

So the function getComponentsInChildren which is called inside Scene.cpp is not found.

Here is the call:

#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();
        }
    }

    ...
}

So I looked inside the GameObject.obj and really there is no symbol containing getComponentInChildren

Here is the 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;
    }

    ...
}

I really dont understand why the Compiler does not output the function to the obj? Is there something I miss or is the error somewhere else?

Kaskorian
  • 426
  • 3
  • 18

0 Answers0