Search⌘ K
AI Features

Header Units

Explore how header units in C++20 serve as a smooth transition from traditional headers to modules, enabling faster compilation and better code organization. Understand the benefits and limitations of header units, including import rules, name export, and the role of module interface and implementation units. This lesson helps you grasp how to replace include directives with import statements to improve modular programming in C++20.

We'll cover the following...

By the end of 2020, no compiler, so far, supported header units. Header units are a smooth way to transition from headers to modules. You just have to replace the #include directive with the new import directive.

C++
#include <vector> => import <vector>;
#include "myHeader.h" => import "myHeader.h";

Why header units?

First, import respects the same lookup rules as include. This means in the case of the quotes ("myHeader.h") that the lookup first searches in the local directory before it continues with the system search path.

Second, this is ...