クラステンプレートは、明示的特殊化できる。クラステンプレートのメンバーは、明示的特殊化できる。このとき、クラステンプレートの明示的特殊化のメンバーの定義と、クラステンプレートのメンバーの明示的特殊化が、似ているのに微妙に違うので、非常にややこしい。
// プライマリークラステンプレート
template < typename T >
struct X
{
void f() ;
} ;
// プライマリークラステンプレートのメンバーの定義
template < typename T >
void X<T>::f() { }
// クラステンプレートの明示的特殊化
template < >
struct X<int>
{
void f() ;
} ;
// 上記のクラステンプレートの明示的特殊化のメンバーの定義
// 明示的特殊化ではない
// template < >を記述するとエラー
void X<int>::f() { }
// クラステンプレートのメンバーの明示的特殊化
// template < >の記述が必要。
template < >
void X<char>::f() { }
方や明示的特殊化ではなく、方や明示的特殊化なので、このような違いが出るのだが、はために見ると非常に似ていて、ややこしい。
No comments:
Post a Comment
You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.