ネストされたテンプレートとそのテンプレートの特殊化に問題があります。次のクラスがあるとします。
小さなテンプレート クラス
template<class U>
class T {
public:
T(){}
virtual ~T (){}
};
そして、ある種のネストされたテンプレート
template<typename T, template<typename> class U>
class A {
public:
void foo()
{
std::cerr << "A generic foo";
}
};
そして小さな main.cpp
int main(int argc, const char *argv[])
{
A<int,T> *a = new A<int,T>;
a->foo();
//This wont work:
A<double,T*> *b = new A<double,T*>;
b->foo();
return 0;
}
U がポインターの場合、特殊化が必要です。
A<double,T*> *b = new A<double,T*>;
b->foo();
これを達成する方法は?私は次のようなものを試しました:
template<typename T, template<typename> class U>
class A< T, U* >
{
public:
void foo()
{
std::cerr << "A specialized foo";
}
};
しかし、それは単に解決します
A.h:18:16: Error: Templateargument 2 is invalid