#include <iostream> using namespace std; template <int n> class static_logN { public: enum {value = static_logN<n/>::value+ }; } ; template <> class static_logN<> { public: enum{value = }; }; int main() { cout<<static_logN<>::value<<endl; cinget(); } 进一步扩展可以写出一个求出底为k求log(int k)(int N)的整数部分的程序来如下: #include <iostream> using namespace std; template <int baseint n> class static_logxN { public: enum {value = static_logxN<basen/base>::value+ }; } ; template <int base> class static_logxN<base> { public: enum{value = }; }; int main() { cout<<static_logxN<>::value<<endl; cinget(); } |