vendredi 6 mars 2020

Unresolved External Symbol calling inherited class function [duplicate]

I'm trying to have a class call a function from an inherited class however whenever I do I get an unresolved external error LNK2019. I'm confused to why this is happening as all of the files appear to be properly included, I haven't overridden the function & Visual Studio doesn't complain about it prior to compiling.

I've tried:

  • Running the replacing the function call with the actual code, this fixes one of the two errors but I still get an unresolved external as the functions in question are calling another function from another class.

  • Messing around with namespaces, as the inherited class is under a separate namespace I thought that was the problem e.g. Memory::Allocate(...).

  • Directly calling the class function, so instead of Allocate(...) I tried Memory::GlobalMemoryUser::Allocate(...)

  • Calling the function using this->...

Relevant code from GlobalMemoryUser.h

#include "MemoryManager"

namespace Memory
{
    namespace Internal
    {
        extern MemoryManager* GlobalMemoryManager;
    {

    class GlobalMemoryUser
    {
    public:

        // Allocator and deallocator
        inline const void* Allocate(size_t, const char* user);
        inline const void DeAllocate(void*);

    private:

        // A pointer to the global memory manager
        Internal::MemoryManager* GlobalMemoryManager;
    };
}

Relevant code from GlobalMemoryManager.cpp

#include "GlobalMemoryUser.h"

namespace Memory {

    const void* GlobalMemoryUser::Allocate(size_t size, const char* user)
    {
        return GlobalMemoryManager->Allocate(size, user);
    }

    const void GlobalMemoryUser::DeAllocate(void* p)
    {
        GlobalMemoryManager->DeAllocate(p);
    }
}

Relevant code from System Manager.h

#include "GlobalMemoryUser.h"

namespace ECS
{
    class SystemManager : public Memory::GlobalMemoryUser
    {
        // Constructor and Deconstructor
        SystemManager();
        ~SystemManager();
    };
}

Relevant code from SystemManager.cpp

#include "SystemManager.h"

namespace ECS
{
    SystemManager::SystemManager()
    {
        systemAllocator = new Memory::LinearAllocator(ECS_SYSTEM_MEMORYBUFFERSIZE, Allocate(ECS_SYSTEM_MEMORYBUFFERSIZE, "SystemManager"));
    }


    SystemManager::~SystemManager()
    {
        for (std::vector<ISystem*>::reverse_iterator it = systemWorkOrder.rbegin(); it != systemWorkOrder.rend(); it++)
        {
            (*it)->~ISystem();
            *it = nullptr;
        }

        systemWorkOrder.clear();
        systemsTable.clear();

        DeAllocate((void*)systemAllocator->GetUsedMemoryStart());
        delete systemAllocator;
        systemAllocator = nullptr;
    }
}

The errors in question happen within the constructor and deconstructor for the system manager when trying to call the allocator and deallocator from the GlobalMemoryUser parent class.

Exact Error Message: LNK2019 unresolved external symbol "public: void const * __cdecl Memory::GlobalMemoryUser::Allocate(unsigned __int64,char const *)" (?Allocate@GlobalMemoryUser@Memory@@QEAAPEBX_KPEBD@Z) referenced in function "public: __cdecl ECS::SystemManager::SystemManager(void)" (??0SystemManager@ECS@@QEAA@XZ)

Aucun commentaire:

Enregistrer un commentaire