如何将模块拆分为多个文件

时间:2016-08-26 08:21:05

标签: c++ c++20 c++-modules

我在c ++中读到了关于模块的内容,而且有些东西我真的不明白该怎么做。我想知道如何使用当前的合并模块提议将c ++模块有效地拆分成多个文件。

假设我有两个要导出的类。我想拆分我的ixx文件,以便每个类的实现都保留在单独的文件中。

我想象了这样的事情:

interface.ixx:

export module MyModule;

export namespace MyLib {
    struct A {
        void doStuff();
    };

    struct B {
        A myA;
        void otherStuff();
    };
}

然后,我想实现我的类,

A.ixx:

module MyModule;

// import self??

MyLib::A::doStuff() {
    // stuff...
}

B.ixx

module MyModule;

// import self again??

MyLib::B::otherStuff() {
    myA.doStuff();
}

我想知道的是:一个模块,无论文件是什么,都知道它的界面?如果没有,是否有另一种方法将模块拆分为多个文件?我知道在这种情况下看起来似乎很愚蠢,但是在大型模块中使用大型类,将事物分开是很诱人的。

1 个答案:

答案 0 :(得分:1)

merged module proposal中,[module.unit] / 8:

  

既不包含export也不包含 module-partition module-declaration ,则隐式地导入模块的主要模块接口单元,就像通过 module-import-declaration

这意味着模块实现单元会隐式导入模块的主模块接口。

相关问题