-
Book Overview & Buying
-
Table Of Contents
Software Architecture with C++ - Second Edition
By :
Ideally, the best option is to start a new project using C++ modules, but this is not always possible, especially with existing code bases. Therefore, many C++ libraries provide both C++ header files and module interface units, so as not to break compatibility. This approach ensures gradual migration by using the C++ module interface unit to include C++ headers and re-export their entities.
The following code from customer.h shows how this approach works in practice. These header and source files are quite traditional for C++ programs:
namespace trade_fair {
using CustomerId = int;
CustomerId get_current_customer_id();
}
The following code from customer.cpp defines the function declared in customer.h:
trade_fair::CustomerId trade_fair::get_current_customer_id() { return 42; }
customer.cppm re-exports the declarations from the customer header file. The export block is applied to group many declarations:
module;
#include...