外部クラスにテンプレートパラメータがある場合、ネストされたクラスのアウトラインコンストラクタを提供しようとしています。内部クラスはデータメンバの宣言によってのみ異なります。以下は私のMCVEです。もしそれが最小限に抑えられれば私の謝罪。外部クラスがテンプレート化されているときにネストされたクラスのアウトラインコンストラクタ
typedef unsigned char byte;
template<class W, bool B>
struct F
{
struct G;
};
template class F<int, false>;
template class F<long, true>;
template<>
struct F<int, false>::G
{
G();
byte b[4];
};
template<>
struct F<long, true>::G
{
G();
byte b[6];
};
template<>
F<int, false>::G::G()
{
b[0] = b[1] = b[2] = b[3] = 0;
}
template<>
F<long, true>::G::G()
{
b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = 0;
}
int main(int argc, char* argv[])
{
return 0;
}
上記から、私は単純にF::G::G
がラインから外れて欲しいと思います。
私はそれをコンパイルしようとすると、それは、その結果:
test.cxx:29:1: error: template-id ‘G<>’ for ‘F<int, false>::G::G()’ does not match any template declaration
F<int, false>::G::G()
^
test.cxx:35:1: error: template-id ‘G<>’ for ‘F<long int, true>::G::G()’ does not match any template declaration
F<long, true>::G::G()
^
にはどうすればG
のためのアウトオブラインのコンストラクタを提供していますか?
機能に焦点を当てる他の同様の質問があります。私の切断は、データメンバが痛みを伴うときにこれを動作させているようです。ら
- How to explicitly instantiate a template class that has a nested class with a friend function
- Template method of template class specialization
- Specialization of template method in partial class specialization
- 。
は、ここで私が何をしようとしていますものです。 C++ではこれが簡単ではないので、コンパイル時の宣言を得るためにはテンプレートの特殊化に頼らざるを得ませんでした。
template<class W, bool B>
struct F
{
struct G
{
#if (B == true)
byte b[6];
#else
byte b[4];
#endif
};
};
'G'コンストラクタは[私のために働く](http://ideone.com/u65mFa)。 –