Hello big brains of the internet :). I am making my way deeper into the depths of C++. I received this error and even tho it should be an easy one, I don't have the faintest idea where have I made mistake.
Here is a declaration of the template etc.:
using ComponentID = std::size_t; inline ComponentID getComponentTypeID() { static ComponentID lastID = 0; return lastID++; } template <typename T> inline ComponentID getComponentTypeID() noexcept { static ComponentID typeID = getComponentTypeID(); return typeID; } This is the code of the whole class of an Entity Component System I am currently working on:
class Entity { private: bool active = true; std::vector<std::unique_ptr<Component>> components; ComponentArray componentArray; ComponentBitSet componentBitSet; public: void update() { for (auto& c : components) c->update(); for (auto& c : components) c->draw(); } void draw() {} bool isActive() const { return active; } void destroy() { active = false; } template <typename T> bool hasComponent() const { return componentBitSet[getComponentTypeID<T>()]; } template <typename T, typename... TArgs> T& addComponent(TArgs&&... mArgs) { T* c(new T(std::forward<TArgs>(mArgs)...)); c->entity = this; std::unique_ptr<Component> uPtr{ c }; components.emplace_back(std::move(uPtr)); ComponentArray[getComponentTypeID<T>()] = c; ComponentBitSet[getComponentTypeID<T>()] = true; c->init(); return *c; } template<typename T> T& getComponent() const { auto ptr(componentArray[getComponentTypeID<T>()]); return *static_cast<T*>(ptr); } }; The mistake should be somewhere along this line:
ComponentArray[getComponentTypeID<T>()] = c; I tried checking it, rewriting it, my roomie checked it over, but my eyes decieve me... Please help?
https://stackoverflow.com/questions/66467141/error-s2760-unexpected-token-expected-inside-a-ecs March 04, 2021 at 09:06AM
没有评论:
发表评论