首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模板还可以这样递归.解决办法

2012-03-01 
模板还可以这样递归...C/C++ code#include iostreamusing namespace stdconst unsigned P 10templat

模板还可以这样递归...

C/C++ code
#include <iostream>using namespace std;const unsigned P = 10;template <unsigned P> struct test{    static void func()    {        cout << "func: " << P << endl;        test<P - 1>().func();    }}; struct test<0>{    static void func()    {        cout << "func0" << endl;    }};int main(){    test<P>::func();    return 0;}


[解决办法]
不错,有机会也来用看看
[解决办法]
模板...最近想开始学了..
[解决办法]
C++模板元编程,一直没看。

[解决办法]
模板,我一直很头疼的东东

[解决办法]
这是 元编程 的其中的一个基础。
[解决办法]
貌似挺實用的~
[解决办法]
C/C++ code
#include <iostream>using namespace std;const unsigned P = 10;template <unsigned P>struct test{    static void func()    {        cout << "func: " << P << endl;        test<P - 1>::func();//这里直接使用::操作符调用就行了,没必要使用对象调用func静态成员函数了    }};template<>//这里应该是特化struct test<0>{    static void func()    {        cout << "func0" << endl;    }};int main(){    test<P>::func();    return 0;}
[解决办法]
貌似挺實用的~
[解决办法]
学习了
[解决办法]
MPL基础嘛

热点排行