How can I pass a span of an array to a base class? If that’s not possible, how about passing a const ref to the array? The issue is that both the span and the array require an explicit size as template argument, so the base class needs that size. Currently, I’m doing this with a vector.
I’m trying to do something like:
enum Seasons {
Spring, Summer, Fall, Winter
};
struct Base {
template<size_t N>
Base(std::span<Seasons, N> list) {}
};
struct Derrived : Base {
inline static const std::array mValues = {
Spring, Winter
};
Derrived() : Base(???) {}
};
>Solution :
To deduce std::span template parameters you should call the constructor:
struct Base {
template <std::size_t N>
Base(std::span<const Seasons, N> list) {}
// ^^^^^
// T must be const for const std::array
};
struct Derrived : Base {
inline static const std::array mValues = {Spring, Winter};
Derrived() : Base(std::span(mValues)) {}
};