C++ enum casting and templates
- by JP
I get the following error with VS2008: Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
When casting a down casting a ClassA to ClassA_1 and ClassA_1 is a templated class that received an enum for parameter such as:
ClassA
{
virtual ~ClassA(){};
}
template <class Param1>
ClassA_1 : public ClassA
{
public:
//constructor
ClassA_1(Param1 p1)
{
_p1 = p1;
}
Param1 _p1;
}
So I have a upcasted
ClassA a = new ClassA_1<myenum>();
When I need to do this:
ClassA_1<myenum> a1 = (ClassA_1<myenum> a); // This fails ...
The only way it works is:
ClassA_1<int> a1 = (ClassA_1<int> a);
but this break my template as it must always deal with int...
How to properly cast a enum that is now a int, back into the enum?