提问人:Vittorio Romeo 提问时间:4/3/2023 更新时间:4/3/2023 访问量:180
显式模板实例化定义的“显式默认定义”错误 (Clang VS GCC)
"definition of explicitly-defaulted" error with explicit template instantiation definition (Clang VS GCC)
问:
请考虑以下代码:
template <typename> struct S { S(); };
// extern template struct S<int>;
template <typename T> S<T>::S() = default;
template S<int>::S();
clang++
愉快地接受这个代码。
g++
投诉:
error: definition of explicitly-defaulted 'S< <template-parameter-1-1> >::S()
[with <template-parameter-1-1> = int]'
3 | template <typename T> S<T>::S() = default;
| ^~~~
取消注释修复编译(并且仍然很高兴)。extern template
g++
clang++
g++
拒绝代码是否正确?
答: 暂无答案
评论
=default;