模板的定义必须在需要之前从模块中导入
Definition of template must be imported from module before it is required
我想要 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++20 草案(与 Modules TS 有很大不同),该程序是有效的:export
影响名称查找,而不是任何更抽象的“可用性”概念。人们可以通过多种方式中的任何一种获得对非导出 my_template
的访问权限,包括从类型是其特化之一的对象中推导模板参数。
我想要 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++20 草案(与 Modules TS 有很大不同),该程序是有效的:export
影响名称查找,而不是任何更抽象的“可用性”概念。人们可以通过多种方式中的任何一种获得对非导出 my_template
的访问权限,包括从类型是其特化之一的对象中推导模板参数。