I have these two source files that compile and link without any problem.
a.cpp
enum class numbers
{
one,
two,
};
const char* getName(numbers number)
{
switch (number)
{
case numbers::one:
return "one";
break;
case numbers::two:
return "two";
break;
}
}
b.cpp
#include <iostream>
enum class numbers
{
zero,
one,
two,
};
const char* getName(numbers number);
void print(numbers number)
{
std::cout << getName(number);
}
int main()
{
print(numbers::one);
return 0;
}
As you can see the same enum class is defined differently in each file. I am looking for a way to catch these kind of conflicts of enum classes (causing bugs in our very very big code base) in different translation units. Does any compiler/linker has the capability to generate error in such situation?