template<int J>
class A
{
public:
enum{
J = A<J-1>::J *2,
};
};
template<>
class A<0>
{
public:
enum{
J = 1,
};
};
template<int N>
class Test{
public:
static int const res = Test<N-1>::res + Test<N-1>::res;
};
//结束递归的局部特化
template<>
class Test<0>{
public:
static int const res = 1;
};
int _tmain(int argc, _TCHAR* argv[])
{
Test<2> t;
std::cout<<t.res<<std::endl;
cout<<A<3>::J<<endl;
getchar();
}
模板元
最新推荐文章于 2024-01-07 11:48:06 发布