r/cpp • MSVC user, r/cpp_modules • Mar 29 '26

Organizing C++ Module Sources

https://abuehl.github.io/2026/03/26/organizing-module-sources.html

A quote from the blog:

The source files for a specific partition are now grouped together into a dedicated sub-directory.

Thanks in advance for your comments to this blog posting!

16 Upvotes

8 comments sorted by

View all comments

Show parent comment

2

u/tartaruga232 MSVC user, r/cpp_modules Mar 30 '26

Thanks for your comment. It's an intentional design decision. In the specific case of our Core module, usage of the module cannot be meaningfully split. The classes declared in Core are too tightly coupled. For example, we have class Core::IElement. It uses class Core::Transaction and vice-versa. These are declared in different partitions of the Core module, but you cannot use class IElement without class Transaction. C++ allows to use forward declarations of classes across module partitions, but you cannot do that across module boundaries. With header files, it was possible to forward declare classes in a header. That's no longer possible with modules. See my blog posting "Converting a C++ Application to Modules". If you have a reference or a pointer to an object of a class declared in Core, you need to import Core. You cannot forward declare Core::IElement outside of module Core.