TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
export keyword in C++20 modules dictates the external linkage and visibility of entities within a module interface unit. It explicitly designates which declarations and definitions are accessible to other translation units that import the module, establishing the module’s public interface while keeping unexported entities strictly encapsulated within the module’s purview.
Primary Module Interface Declaration
To define a translation unit as the primary interface for a module, theexport keyword must precede the module keyword. This must be the first non-comment, non-preprocessor line in the file (following the optional global module fragment).
Exporting Declarations
You can export entities such as functions, classes, variables, templates, and aliases. Theexport specifier can be applied to individual declarations, grouped in blocks, or applied to entire namespaces.
Exporting Imports (Transitive Inclusion)
A module can re-export another module or header unit. Any translation unit that imports the current module will implicitly import the re-exported module.Technical Constraints and Linkage Rules
- Namespace Scope Requirement: The
exportkeyword can only appear at namespace scope (either the global namespace or a named namespace). It cannot be used at block scope (inside functions) or class scope (inside class definitions).
- Linkage Restrictions: You cannot export entities that possess internal linkage. This includes variables or functions marked
static, or entities declared within an unnamed (anonymous) namespace.
- Declaration Order: If an entity is exported, its first declaration in the translation unit must contain the
exportspecifier. Subsequent declarations or definitions of that same entity in the same translation unit do not require theexportkeyword, though it is permitted.
- Implicit Exports: When a class or struct is exported, all of its public, protected, and private members are implicitly exported. However, private and protected members remain subject to standard C++ access control rules; they are visible to the compiler in the importing translation unit (for memory layout and instantiation purposes) but cannot be accessed directly.
Master C++ with Deep Grasping Methodology!Learn More





