Test2
私は 2 つのテンプレート引数を取るテンプレート化された class( ) を作成しようとしていType1
ますType2
。2 番目の引数も、2 つのテンプレート引数 (TypeA
およびTypeB
) を取るテンプレート化されたクラスになることが知られています。
ここで、 のオブジェクトを作成するためにTest2
、ユーザーが 2 種類のコンストラクターのいずれかを使用できるようにしたいと考えています。
Type1
とのオブジェクトを取るものType2
。Type1
、TypeA
およびのオブジェクトを取るものTypeB
。
次のコードを書きました。
#include <iostream>
template<class TypeA, class TypeB>
struct Test
{
TypeA t1obj;
TypeB t2obj;
Test(const TypeA& t1, const TypeB& t2)
: t1obj(t1), t2obj(t2) {std::cout<<"Test::Type1, Type2\n";}
};
template<class Type1,
template<typename TypeX, typename TypeY> class Type2 >
struct Test2
{
Type1 t1obj;
Type2<typename TypeX, typename TypeY> t2obj; //Line 17
Test2(const Type1& t1,
const Type2<typename TypeX, typename TypeY>& t2) //Line 20
: t1obj(t1), t2obj(t2) { std::cout<<"Test2::Type1, Type2\n";}
Test2(const Type1& t1,
const TypeX& x,
const TypeY& y)
: t1obj(t1), t2obj(x,y) { std::cout<<"Test2::Type1, X, Y\n";}
};
int main()
{
Test<int, char> obj1(1,'a');
Test2<int, Test<int, char> > strangeobj1(10,obj1);
Test2<int, Test<int, char> > strangeobj2(1,2,'b');
}
私は多くのことを試しましたが、次のような非常にばかげたエラーが発生します。
wrong number of template arguments (1, should be 2)
17号線と20号線で。