Suppose there is a C++11 API that uses enum classes:
// api.hpp
enum class E {A, B, C};
void f(E);
...
// api.cpp
void f(E e)
{
if (e == E::A)
...
}
Now suppose I would like to use this API, but I don't have a C++11 compiler. So I:
- Modify
api.hpp
and change the enum class to be just a regular enum. - Write some code code that includes the modified
api.hpp
and uses the API normally (e.g. callsf
). - Compile this code with my non-C++11 compiler and link it to the API implementation which was compiled with a C++11 compiler (using the unmodified
api.hpp
).
This seems to work with GCC, but is it safe in general, or am I playing with fire (ODR violations and such)?
Assume the two compilers are otherwise link-compatible, it is only the enum vs. enum class that is at issue.