I have encountered a problem while dealing with template specialization. I'd like to have method that has an enum as argument and depending on it call specialized templated method. Heres the presentation:
#include <iostream>
enum EnumType
{
ENUM1,
ENUM2,
ENUM3
};
class Test
{
public:
template <EnumType enumType>
bool enumFunc(const int i )
{
std::cout << i << " default\n";
return false;
}
bool func(const EnumType e);
};
template<>
bool Test::enumFunc<ENUM2>(const int i )
{
std::cout << i << " ENUM2 \n";
return true;
}
//... and other specializations
bool Test::func(const EnumType e)
{
// this one works
// return enumFunc<ENUM2>(3);
// but this:
// error: no matching function for call to 'Test::enumFunc<e>(int)
return enumFunc<e>(3);
}
int main()
{
Test a;
a.enumFunc<ENUM2>(2); // works
a.func(ENUM2); // doesnt even get there due to previous error
return 0;
}