2012-07-14 49 views
5

可能重複:
Template Metaprogramming - Difference Between Using Enum Hack and Static ConstPOW(功率)的模板從維基實施

請解釋什麼是enum在下面的執行力模板的使用。

template<int B, int N> 
struct Pow { 
    // recursive call and recombination. 
    enum{ value = B*Pow<B, N-1>::value }; 
}; 

template< int B > 
struct Pow<B, 0> { 
    // ''N == 0'' condition of termination. 
    enum{ value = 1 }; 
}; 
int quartic_of_three = Pow<3, 4>::value; 

我是在維基百科上找到它的。在這種情況下,intenum之間有區別嗎?

+0

@user - 'enum'工作了一些老的編譯器,如Borland的C++,它不支持'靜態常量int'。 – 2012-07-14 12:22:54

回答