Для этого я определил следующие классы:
Код: Выделить всё
class Component
{
public:
virtual ~Component() {}; // Ensure polymorphic behavior with a virtual destructor
};
class TransformComponent : public Component
{
glm::vec2 position = {0.0f, 0.0f};
float rotation = 0.0f;
float scale = 1.0f;
};
using identifier = uuids::uuid;
class Entity {
private:
identifier id;
bool isActive = true;
std::string name = "new entity";
std::vector components;
public:
Entity() : isActive(true), id( UUID::get()), name("NEW") {};
~Entity() = default;
// Disable copying
Entity(const Entity&) = delete;
Entity& operator=(const Entity&) = delete;
// Define move constructor and move assignment
Entity(Entity&& other) noexcept;
Entity& operator=(Entity&& other) noexcept;
template
T* GetOrAdd() {
static_assert(std::is_base_of::value, "T must be derived from Component");
for (auto& comp : components) {
if (auto result = dynamic_cast(comp.get())) {
return result;
}
}
auto newComp = std::make_unique();
T* result = newComp.get();
components.push_back(std::move(newComp));
return result;
}
Код: Выделить всё
class Scene {
public:
Scene(std::string sceneName, bool isEditorMode);
~Scene();
private:
std::unique_ptr ent = std::make_unique();
}
Код: Выделить всё
D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.cpp: In constructor 'gl3::HierarchyPanel::HierarchyPanel()':
D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.cpp:9:52: error: use of deleted function 'gl3::Scene& gl3::Scene::operator=(const gl3::Scene&)'
9 | currentScene = *GlobalHelper::GetScenes()[0];
| ^
In file included from D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.h:4,
from D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.cpp:1:
D:/Projects/searchengineproject/vocabulary/game/src/entities/Scene.h:21:11: note: 'gl3::Scene& gl3::Scene::operator=(const gl3::Scene&)' is implicitly deleted because the default definition would be ill-formed:
21 | class Scene {
| ^~~~~
D:/Projects/searchengineproject/vocabulary/game/src/entities/Scene.h:21:11: error: use of deleted function 'std::unique_ptr& std::unique_ptr::operator=(const std::unique_ptr&) [with _Tp = gl3::Entity; _Dp = std::default_delete]'
In file included from D:/Program Files/CLion 2022.3.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/locale_conv.h:41,
from D:/Program Files/CLion 2022.3.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/locale:43,
from D:/Program Files/CLion 2022.3.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/fs_path.h:37,
from D:/Program Files/CLion 2022.3.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/filesystem:45,
from D:/Projects/searchengineproject/vocabulary/game/src/rendering/Texture.h:6,
from D:/Projects/searchengineproject/VokabelTrainer/game/src/GlobalHelper.h:3,
from D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.h:3,
from D:\Projects\searchengineproject\vocabulary\game\src\rendering\HierarchyPanel.cpp:1:
D:/Program Files/CLion 2022.3.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/unique_ptr.h:469:19: note: declared here
469 | unique_ptr& operator=(const unique_ptr&) = delete;
| ^~~~~~~~
mingw32-make[3]: *** [game\CMakeFiles\game_lab_3.dir\build.make:316: game/CMakeFiles/game_lab_3.dir/src/rendering/HierarchyPanel.cpp.obj] Error 1
mingw32-make[3]: *** Waiting for unfinished jobs....
mingw32-make[2]: *** [CMakeFiles\Makefile2:2095: game/CMakeFiles/game_lab_3.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:2102: game/CMakeFiles/game_lab_3.dir/rule] Error 2
mingw32-make: *** [Makefile:1047: game_lab_3] Error 2
Что я мог упустить?
Подробнее здесь: https://stackoverflow.com/questions/787 ... tr-tp-dpop