I\'m trying to create a structure array which links input strings to classes as follows:
struct {string command; CommandPath cPath;} cPathLookup[] = {
{\
You can't store a type in a struct, but you can store a pointer to a function that creates a type.
CommandPath * CreateEmail() {
return new EmailCommandPath;
}
CommandPath * CreateAlarm() {
return new AlarmCommandPath;
}
Then your struct looks like:
typedef Command * (* CreateFunc)();
struct MyMap {
string command;
CreateFunc func;
};
and the map:
MyMap m[] = {{"email", CreateEmail }, {"alarm", CreateAlarm}};
You then look up as before to get some index i, and use it:
CommandPath * p = m[i].func():
And you can create pointers to abstract types - you can't create instances of them.