Using C++ modules
Modules were introduced in C++20 as an alternative means of sharing declarations/definitions across multiple translation units; essentially, they are a partial replacement for header files. These are similar to how other programming languages, such as Rust, organize their code; entities are organized into modules (derived primarily from the file structure). Modules do not replace namespaces; you should continue to use these in addition to modules. An interface module is declared using an export module statement. In the following code snippet, we declare a new module named computational_thinking (in module_example.cpp). Entities that should be exported in the module must be prefixed with the export keyword; we include some examples here:
export module computational_thinking;
export namespace ct {
// defined elsewhere
void exported_fn(int a);
}
// Not exported
int non_exported_fn();
// defined elsewhere
export int another_exported_fn(int b);
// exported...