Using C++ type aliasing to avoid the ODR problem with conditional compilation

5 signa11 2 5/3/2025, 7:01:56 AM devblogs.microsoft.com ↗

Comments (2)

cherryteastain · 14h ago
Cool trick but why wouldn't you just put the Log method without the ifdef in the header, and put the conditionally compiled bits in a .cpp file? The method in the article already puts both Widget<true> and Widget<false> in a .cpp file.
stop50 · 12h ago
The thing that is complained on by the linker is not the method, its the m_logger attribute. because of that the two structs mismatch. But since Widget<true> and Widget<false> are two different structs in the typing system they don't interfere with each other