Reputation: 41760
I read about modules in c++ and there's something I can't really understand how to do. I wonder how you can effectively split a c++ module into multiple files with the current merged module proposal.
Let's say I have two classes that I want to export. I want to split up my ixx files so the implementation of each of these classes stay in separated files.
I imageined something like this:
interface.ixx:
export module MyModule;
export namespace MyLib {
struct A {
void doStuff();
};
struct B {
A myA;
void otherStuff();
};
}
Then, I would like to implement my classes like this,
A.ixx:
module MyModule;
// import self??
MyLib::A::doStuff() {
// stuff...
}
B.ixx
module MyModule;
// import self again??
MyLib::B::otherStuff() {
myA.doStuff();
}
What I want to know: Is a module, regardless the file, is aware of it's interface? If not, is there another way to split a module into mutiple files? I know it might seem silly in that case but with large classes within large module, it would be tempting to keep things separated.
Upvotes: 4
Views: 1758
Reputation: 41760
In the merged module proposal, [module.unit]/8:
A module-declaration that contains neither
export
nor a module-partition implicitly imports the primary module interface unit of the module as if by a module-import-declaration.
This means that a module implementation unit implicitly imports the primary module interface of the module.
Upvotes: 2