导出从另一个模块导入的类

时间:2018-05-06 15:30:28

标签: c++ clang++ c++-modules

我正在使用clang 5.0试验C ++模块,我试图了解如何从一个模块导出我从另一个模块导入的内容。这甚至可能吗?

例如,我想要这样的东西:

// root.hehe.cppm
export module root.hehe;

class hehe
{    
};

和此:

// root.cppm
export module root;

import root.hehe;

export class hehe; // ... doesn't work!
export hehe; // Also doesn't work!
export import root.hehe; // No dice!

所以最后我可以做一些像

这样的事情
import root;

// ...

hehe myhehe;

这样的事情可能吗?我还试图弄清楚是否可以导入root的所有子模块,如import root.*,但这也不起作用。

1 个答案:

答案 0 :(得分:0)

在C ++ 20(不是Clang中的任何原型版本)中,您可以使用

export using ::hehe;
export using hehe=hehe;

为此,有两个警告:

  1. 第一种形式必须始终使用合格的名称(因为很早以前就引入了语法,用于在 名称空间之间复制名称)。
  2. 您必须首先能够使用您导入的名称,在您的示例中情况并非如此,因为root.hehe没有导出它。 (对于类型别名方法,只需通过decltype命名即可。)

您还可以使用export import root.hehe;重新导出要导入的模块导出的所有内容。没有通配符导入语法:带点的模块名称不具有没有语义(在C ++ 20中)。

相关问题