【发布时间】:2019-07-27 17:15:59
【问题描述】:
我有以下编译好的代码:
template <typename T>
struct A {T t;};
template <typename T> // 1
A(T) -> A<T>; // function template declaration with trailing return type compiles fine.
但同一函数声明的以下变体无法编译:
template <typename T> // 2
auto A(T) -> A<T>; // error: redefinition of 'A' as different kind of symbol
template <typename T> // 3
A<T> A(T); // error: redefinition of 'A' as different kind of symbol
请帮助我理解为什么那些没有编译的原因
【问题讨论】:
-
问这样的问题时,一定要提供编译错误的文本。
-
@NeilButterworth 添加了实际的编译错误消息。谢谢
标签: c++ templates c++17 template-argument-deduction function-templates