r/cpp • u/holyblackcat • Mar 09 '26
The compilation procedure for C++20 modules
https://holyblackcat.github.io/blog/2026/03/09/compiling-modules.html
101
Upvotes
r/cpp • u/holyblackcat • Mar 09 '26
View all comments
Show parent comment
5
u/not_a_novel_account cmake dev Mar 09 '26 edited Mar 09 '26
That's exactly what this example does, the implementation file (
partition.cpp) provides the definition for theint add(int, int)declared in the interface (partition.cppm).This is verified in the
main.cpptest, which uses the declaration from the interface to accessadd(int, int).EDIT: Added a class method to demonstrate it doesn't matter if this is a free function or a method. The only difference is you need to import the interface into the implementation file, same like you would need to include a header, to have access to the class definition.
EDIT2: Ooof, and it fails on MSVC. TIL. That's a nasty bug. Ok, more work to do, all the more reason for a paper.