Hi
I want to test out a polymorphic entity component system where the idea is that the components of an entity are "compositioned" using templated multiple inheritance. But I am running into an issue because I am stacking a bunch of methods with the same names inside a class (but they have different signatures). I want these methods to be overloaded by the template type but my compiler says the access is ambiguous. I have issues making them unambiguous with the using declaration because the paramter pack expansion causes a syntax error.
Can anyone here give me some advice on this?
template <class T>
class component
{
T m_data;
protected:
component() {};
~component() {};
public:
void set(const T& data) { m_data = data; };
};
template <class ...Ts>
class entity : public component<Ts>...
{
public:
entity() {};
~entity() {};
//using component<Ts>::set...; // syntax error
};
struct position { float x{}; float y{}; float z{}; };
struct velocity { float x{}; float y{}; float z{}; };
int main()
{
entity<position, velocity> myEntity;
position pos = { 1.0f, 1.0f, 1.0f };
velocity vel = { 2.0f, 2.0f, 2.0f };
myEntity.set(pos); // error C2385: ambiguous access of 'set'
//myEntity.set(vel);
return 0;
}
↧