- 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基础嘛