Search⌘ K

Module Interface Unit and Module Implementation Unit

Explore how to divide a C++20 module into a single interface unit and multiple implementation units. Understand exporting declarations, organizing code effectively, and compiling modules using the Microsoft compiler. This lesson helps you improve module management and build modular C++20 programs efficiently.

When the module becomes bigger, you should structure it into a module interface unit and one or more module implementation units. Following the previously mentioned guidelines to structure a module, I will refactor the previous version of the math module.

Module interface unit

C++
// mathInterfaceUnit.ixx
module;
#include <vector>
export module math;
export namespace math {
int add(int fir, int sec);
int getProduct(const std::vector<int>& vec);
}
  • The module interface unit ...