Search⌘ K

A First Example

Explore the basics of C++20 modules by writing a simple math module. Learn how to declare, export functions, and import modules to improve code structure and compilation efficiency.

We'll cover the following...

The purpose of this section is straightforward: I will give you an introduction to modules. More advanced features of modules are in the following sections. Let’s start with a simple math module, written in the math.ixx file.

C++
// math.ixx
export module math;
export int add(int fir, int sec){
return fir + sec;
}

The expression export module math is the module declaration. By putting export before function add's definition, ...