❔ template function cant convert despite constraint
hi, so im working on a basic ECS kind of thing for my game, and im trying to make a method that returns a list<T> given a T, where T is a component. for some reason, it cant convert T to component despite the constraint that T will always be a component
10 Replies
changing List<T> to List<Component> in the return type fixes it, but isnt what i want
what type does
GetAll
return?List<Component>
i had the same issue back there
it should return List<T>
the problem is you're constraining T to be a Component, but that doesn't mean a Component is a T
well it looks like this problem goes really far back
into my code
to where i was trying to have a processor class for each component
i made an abstract ComponentProcessor class with abstract methods that work with a Component type
and then i made ComponentProcessor<T> to get more specific
but i still need to refer to them all as ComponentProcessor not ComponentProcessor<T>
so i can store them in a list together
so ive got this interface
actually im just gonna hide the dictionary so it doesnt have to be generalized
based on the naming convention it definitely shouldn't be public
it also generally sounds like an implementation detail and shouldn't be visible to consumers
yeah i know i realized that as i was doing this
i just made the components array private
so i can manage every use of it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.