[英]Out of class constructor definition for a specialized class template
我正在嘗試為類定義之外的顯式專用類模板定義構造函數,如下所示:
template <typename T>
struct x;
template <>
struct x<int> {
inline x();
/* This would have compiled:
x() {
}
*/
};
template <> // Error
x<int>::x() {
}
但這似乎是一個錯誤。 Comeau說: error: "x<int>::x()" is not an entity that can be explicitly specialized
,即使完整的類是專門的。
這是什么問題?
不要為定義指定template<>
:
template <typename T>
struct x;
template <>
struct x<int> {
x();
};
inline x<int>::x(){}
編輯:構造函數定義不是特化,因此template<>
是不必要的。 它是專業化構造函數的定義。 因此,您只需要為任何其他非模板類指定類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.