同じテンプレート タイプの 2 つのテンプレート A と B があります。A は常に B から継承しますが、A 自体が使用するのと同じテンプレートを常に B に選択します。
これ自体は問題ありませんが、テンプレート タイプを 2 回記述する必要があります。サブクラスから継承するときに、Aの型を何らかの形でtypedefし、ジェネリックなtypedef名を参照することは可能ですか?
以下は、コンパイルされないコードの例ですが、私が何をしたいのか明確なアイデアを与えるはずです:
// #1
template <typename T>
struct A
{
typename T type;
// class details here
};
// #2
template <typename T>
struct B
{
// class details here
};
// #3
template <>
struct A<int>
: B<type> // Compiler complains here (type not defined)
//: B<A::type> // Compiler complains here (type not defined)
// I could write ": B<int>" instead, but this is repitition I want to avoid
{
// class specialization details here
};
私は代替ソリューションを受け入れています。これが私にとって重要な理由は、#3 のような大量のコードのリストがあり、(バグを避けるために) 重複を減らしたいからです。