frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

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

https://devblogs.microsoft.com/oldnewthing/20250501-00/?p=111134
5•signa11•7mo ago

Comments

cherryteastain•7mo 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•7mo 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