Entity has a member var of type std::array. Student inherits from Entity, and will need to initialize the std::array member var it inherited. Below is the code I'm using to do this, but it involves casting a brace-enclosed list to std::array. I'm not sure this is the correct or optimal way to do this. Using a brace-enclosed or double brace-enclosed list without the cast results in compilation errors. I've tried several other ways of initializing the std::array member var with no success, so I seem to be stuck with my current method. Is there a better way to do this?:
template<typename... Args> struct Entity {
typedef const char* name_t;
typedef const array<const char*, sizeof...(Args)> source_names_t;
const tuple<Args...> data;
name_t name;
//This will be initialized by derived class Student.
source_names_t source_names;
Entity(
name_t tmp_name
, source_names_t tmp_source_names
)
: name(tmp_name)
, source_names(tmp_source_names)
{}
};
//idnum, fname, lname, married
struct Student : Entity<int, string, string, bool> {
Student()
: Student::Entity(
"student"
//Now Student initializes the array, but does it by casting.
, (source_names_t) {{"id", "lname", "fname", "married"}}
)
{}
};