在另一个模板类中使用模板类参数的模板参数的正确语法是什么?访问模板类A中的X和Y,如模板<template <int X,int Y> class> class A;
例如:如何访问Foo类中的Param的X和Y?
计划:
template < template < int, int > class X1>
struct Foo {
int foo() {
printf("ok%d %d\n", X1::X, X1::Y);
return 0;
}};
template < int X, int Y >
class Param {
int x,y;
public:
Param(){x=X; y=Y;}
void printParam(){
cout<<x<<" "<<y<<"\n";
}
};
int main() {
Param<10, 20> p;
p.printParam();
Foo<Param> tt;
tt.foo();
return 0;
}
这样上面的代码,为printf语句编译器抱怨:
In member function 'int Foo<X1>::foo()':
Line 4: error: 'template<int <anonymous>, int <anonymous> > class X1' used without template parameters
compilation terminated due to -Wfatal-errors.