可以默认类模板中的常规复制构造函数吗?
在以下程序结构模板a
具有consta< int>的构造函数中&
。对于a< int>
应该是复制构建器,可以默认:
template<typename T>
struct A {
A() {}
A(const A<int> &) = default;
};
int main() {
A<int> a;
}
该程序被Clang接受,但GCC和MSVC都以错误:
error C2610: 'A<T>::A(const A<int> &)': is not a special member function or comparison operator which can be defaulted
note: see reference to class template instantiation 'A<T>' being compiled
emo demo拒绝: https://gcc.godbolt.org/z/mn6nmbe1x
哪个编译器在这里正确?
In the following program struct template A
has a constructor from const A<int> &
. For A<int>
it should be copy-constructor, which can be defaulted:
template<typename T>
struct A {
A() {}
A(const A<int> &) = default;
};
int main() {
A<int> a;
}
This program is accepted by Clang, but both GCC and MSVC reject it with the error:
error C2610: 'A<T>::A(const A<int> &)': is not a special member function or comparison operator which can be defaulted
note: see reference to class template instantiation 'A<T>' being compiled
Demo: https://gcc.godbolt.org/z/Mn6nMbe1x
Which compiler is right here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论