You can use specialization:
enum struct TypeEnum : int {
TYPE_1 = 1,
TYPE_2 = 2
};
template<TypeEnum Type>
class A;
template<>
class A<TypeEnum::TYPE_1>
{
public:
A(void) { }
};
template<>
class A<TypeEnum::TYPE_2>
{
public:
A(int _x) {
x = _x;
}
int x;
void operator += (const int& n) {
x = x + n;
}
};
int main() {
A<TypeEnum::TYPE_1> test1;
A<TypeEnum::TYPE_2> test2{1};
test1 += 5; // compiler error should be here
test2 += 5; // OK
return 0;
}