可能重複:
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;
我是在維基百科上找到它的。在這種情況下,int
和enum
之間有區別嗎?
@user - 'enum'工作了一些老的編譯器,如Borland的C++,它不支持'靜態常量int'。 – 2012-07-14 12:22:54