Your class FormDatais the base class Formreceived, however your login function looks like
void login(const Form *f){}
But in your submit function you are trying to pass a base class pointer
T dispatch(const Command command, const FormData *f)
{
switch (command)
{
case LOGIN: login(f);
}
C ++ just won't let you do this. Form * can be implicitly converted to FormData *, but not vice versa.
, :
struct FormData {};
struct Form : public FormData {};
void login(const Form *f){}
enum Command
{
LOGIN
};
template <typename T>
T dispatch(const Command command)
{
return T();
}
template <typename T, typename FormDataType>
T dispatch(const Command command, const FormDataType *f)
{
switch (command)
{
case LOGIN: login(f);
}
return dispatch(command);
}
int main()
{
Form f;
dispatch<void>(LOGIN, &f);
dispatch<void>(LOGIN);
}