I'm trying to understand why this code does not compile:
// test.h
struct Base
{
virtual ~Base{};
virtual void execute() {}
virtual void execute(int) {}
virtual void execute(double) {}
}
template<class T>
struct Test : Base
{
void execute(typename std::enable_if<std::is_void<T>::value, void>::type)
{
// Do A
}
void execute(typename std::enable_if<!std::is_void<T>::value, int>::type t)
{
// Do B
}
};
// main.cpp
Test<void> t;
I get a compiler error: "no type named type".
Same error even if I modify the A version of the code with
std::enable_if<std::is_void<T>::value>
The goal is to create a class that depending on the parameter T creates a different function members. In this case 2, but I'd be interested also in more.
[Edit] I've added the inheritance part I was talking about in the comments.