> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C++ Module Export

The `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, the `export` 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).

```cpp theme={"dark"}
export module core_system;
```

## Exporting Declarations

You can export entities such as functions, classes, variables, templates, and aliases. The `export` specifier can be applied to individual declarations, grouped in blocks, or applied to entire namespaces.

```cpp theme={"dark"}
export module core_system;

// 1. Single Declaration Export
export void initializeSystem();
export struct SystemConfig { int threads; };

// 2. Block Export
export {
    int getSystemStatus();
    constexpr int MAX_THREADS = 16;
    template<typename T> class SystemQueue { /* ... */ };
}

// 3. Namespace Export
// Exports all declarations contained within the namespace
export namespace sys_utils {
    void logEvent();
    class Logger;
}
```

## 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.

```cpp theme={"dark"}
export module core_system;

// Consumers of 'core_system' will also see the exported entities of 'memory_pool'
export import memory_pool; 

// Consumers will also see the contents of the standard header
export import <vector>; 
```

## Technical Constraints and Linkage Rules

1. **Namespace Scope Requirement:** The `export` keyword 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).

```cpp theme={"dark"}
export class Manager {
    export void doWork(); // ERROR: Cannot export class members individually
};
```

2. **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.

```cpp theme={"dark"}
export static int internalCounter = 0; // ERROR: internal linkage

export namespace {
    void helperFunction(); // ERROR: unnamed namespace implies internal linkage
}
```

3. **Declaration Order:** If an entity is exported, its first declaration in the translation unit must contain the `export` specifier. Subsequent declarations or definitions of that same entity in the same translation unit do not require the `export` keyword, though it is permitted.

```cpp theme={"dark"}
export void process(); // First declaration must be exported
void process() { ... } // Definition does not need the keyword
```

4. **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.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
