代码如下: 要点为函数静态 /* ccsdu2004@yahoo.com.cn www.gaimo.net 02.15.2009 */ //dev c++ #include <cstdlib> #include <iostream> //#include <vector> //#include <string> //#include <algorithm> using namespace std; template<int N> class loop { public: static inline void run() { cout << "A-" << N << " "; loop< N-1 >::run(); cout << "B-" << N << " "; } }; template<> class loop<0> { public: static inline void run() { cout << "A-0"; cout << "/n"; cout << "B-0 "; } }; int main(int argc, char *argv[]) { loop<4> l; l.run(); system("PAUSE"); return EXIT_SUCCESS; }