What are C++20 Modules, and how do they fundamentally change the compilation model compared to header files?
Last updated
Headers are textual:
#includepastes and re-parses the header in every translation unit, leaks macros, and needs include guards.A module (
export module M;) is compiled once into a binary interface that consumersimport. Onlyexported names are visible and macros don't leak, giving faster builds and order-independent imports.Caveat: toolchain and build-system support is still maturing, and module interfaces impose build ordering dependencies.