您的位置:首页 > 编程语言

模板元编程神奇的东西.....

2010-03-12 14:46 225 查看
真体现了图灵完备性

代码

/************************************************************************/
/* 模板元编程
/************************************************************************/

#include "stdafx.h"
#include <iostream>
using namespace std;

//原始摸板
template<int Base, int Exponent>
class XY
{
public:
enum { result_ = Base * XY<Base, Exponent-1>::result_ };
};

//用于终结递归的局部特化版
template<int Base>
class XY<Base, 0>
{
public:
enum { result_ = 1 };
};

int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "X^Y<5, 4>::result_ = " << XY<5, 4>::result_;

getchar();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: