专用类模板的类外构造函数定义
我试图在类定义之外为显式专用的类模板定义一个构造函数,如下所示:
template <typename T>
struct x;
template <>
struct x<int> {
inline x();
/* This would have compiled:
x() {
}
*/
};
template <> // Error
x<int>::x() {
}
但这似乎是一个错误。 Comeau 说:错误:“x
,即使完整的类是特化的。
这里有什么问题?
I am trying to define a constructor for an explicitly specialized class template outside the class definition, as so:
template <typename T>
struct x;
template <>
struct x<int> {
inline x();
/* This would have compiled:
x() {
}
*/
};
template <> // Error
x<int>::x() {
}
But it seems to be an error. Comeau says: error: "x<int>::x()" is not an entity that can be explicitly specialized
, even though the complete class is what being specialized.
What's the issue here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要为定义指定
template<>
:编辑:构造函数定义不是专门化的,因此
template<>
是不必要的。这是专门化构造函数的定义。因此,您只需像任何其他非模板类一样指定类型。Don't specify
template<>
for the definition:Edit: The constructor definition isn't a specialization, so
template<>
is unnecessary. It's the definition of the constructor of a specialization. So, you just need to specify the type like for any other non-template class.