【问题标题】:Definition of template must be imported from module before it is required模板的定义必须先从模块中导入才需要
【发布时间】:2019-12-05 17:48:35
【问题描述】:

我想export (C++20) 一个别名模板。 VC++ 2019 编译代码。 Clang 报告错误。哪一个是正确的,为什么?

// file: m.cppm
export module m;

template<typename T> struct my_template {};

export template<typename T> using my_alias = my_template<T>;
// file: main.cpp
import m;
int main() { my_alias<int> v; }
main.cpp:2:28: error: definition of 'my_template' must be imported from module 'm' before it is required
int main() { my_alias<int> v; }
^
m.cppm:3:29: note: previous definition is here
template<typename T> struct my_template {};

【问题讨论】:

    标签: c++ clang clang++ c++20


    【解决方案1】:

    根据当前的 C++20 草案(与模块 TS 显着不同),该程序是有效的:export 影响名称查找,而不是“可用性”的任何抽象概念。可以通过多种方式中的任何一种来访问未导出的my_template,包括从类型是其特化之一的对象推导模板参数。

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 2018-07-08
      • 2016-04-23
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多