Использование внешнего класса в шаблонном методе из dll

Я пытаюсь использовать свой игровой движок во внешнем проекте. Все работает нормально, но у меня есть проблема, когда я пытаюсь создать пользовательский компонент (который наследует от ABhaviour, который является абстрактным классом, представляющим компонент, который можно активировать / отключить).

GameObject.h (экспортируется с помощью __declspec (dllexport))

// [...]

template <typename Class, typename ... Args>
std::shared_ptr<Class> GameObject::AddComponent(Args... args)
{
auto newComp = std::make_shared<Class>(std::forward<Args>(args)...);
m_components[typeid(*newComp).hash_code()] = newComp;
m_components[typeid(*newComp).hash_code()]->SetOwner(*this);
return newComp;
}

// [...]

В другом проекте (который использует мой игровой движок) я пытаюсь создать собственный ABehaviour:

PlayerController.h

#pragma once

#include <ElkGameEngine/Objects/Components/Behaviours/ABehaviour.h>

class PlayerController :ElkGameEngine::Objects::Components::Behaviours::ABehaviour
{
PlayerController() = default;
~PlayerController() = default;

void Update();
};

После этого я добавляю свой пользовательский компонент в свой GameObject «Player»:

main.cpp

#include <ElkGameEngine/ElkGameEngine.h>
#include <ElkGameEngine/Objects/AObject.h>
#include <ElkGameEngine/Objects/Components/AComponent.h>

#include "PlayerController.h"
using namespace ElkGameEngine::Objects::Components;
using namespace ElkGameEngine::Objects::Components::Behaviours;

int main()
{
ElkGameEngine::Managers::EngineManager elkGameEngine;
elkGameEngine.GetSceneManager()->CreateScene("ElkCraft");

auto& player = elkGameEngine.GetSceneManager()->CreateEmptyGameObject("Player");
player.AddComponent<PlayerController>(); /* Here is the problem */

while (elkGameEngine.IsRunning())
{
elkGameEngine.PreUpdate();elkGameEngine.PostUpdate();
}

return EXIT_SUCCESS;
}

Visual Studio недовольна и напечатать мне это:

Severity    Code    Description Project File    Line    Suppression State
Error   C2440   '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>' ElkCraft    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory  1472
Error   C2228   left of '.swap' must have class/struct/union    ElkCraft    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory  1472

Окно вывода:

1>------ Build started: Project: ElkCraft, Configuration: Debug x64 ------
1>Could Not Find C:\Users\adrie\Desktop\GROUP_2\PFA\ElkCraft\*.dll
1>main.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2440: '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(53): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(55): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkcraft\sources\main.cpp(18): note: see reference to function template instantiation 'std::shared_ptr<PlayerController> ElkGameEngine::Objects::GameObject::AddComponent<PlayerController,>(void)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2228: left of '.swap' must have class/struct/union
1>Generating Code...
1>Compiling...
1>PlayerController.cpp
1>Generating Code...
1>Done building project "ElkCraft.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Я думаю, что проблема в том, что мой игровой движок (который представляет собой группу DLL) экспортирует шаблонный метод (AddComponent и другие, такие как GetComponent).

  • Можно ли использовать шаблонный метод из dll с аргументом шаблона класса / структуры из проекта, использующего dll?
  • Я делаю что-то неправильно ?
  • Нужно ли указывать что-то на моем PlayerController, чтобы сделать его «известным / полезным» в методе AddComponent?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector