I’m learning about external linkage in C++ and came across a point in cppreference stating that enum
has external linkage. However, I encountered an issue where no linkage conflict occurs when defining the same enum class in different files within the same namespace.
Here are my code snippets:
test1.cpp:
namespace A {
enum TestEnum{};
}
test2.cpp:
namespace A {
enum TestEnum{};
}
I expected the compiler to raise a linkage conflict error, but it compiles without any issues. Could someone explain why there’s no conflict despite the enums having external linkage? What am I missing about the linkage of enum types in this context?
Thank you in advance for your help!
Qie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1