可能重复: Template Metaprogramming - Difference Between Using Enum Hack and Static Const
请解释在下面的power模板实现中使用了什么for is 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有什么区别吗?
发布于 2012-07-14 12:03:54
如果您尝试获取static const int的地址,则可能会有不同。在这种情况下,编译器将为static const int生成存储。您不能获取enum的地址,编译器将永远不会为它生成存储。
另见Template Metaprogramming - Difference Between Using Enum Hack and Static Const
https://stackoverflow.com/questions/11483568
复制相似问题