use*_*506 5 c++ enums templates
请解释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;
Run Code Online (Sandbox Code Playgroud)
我在维基百科上找到了它.有没有之间的差异int,并enum在这种情况下?
如果你试图获取一个地址可能会有所不同static const int.在这种情况下,编译器将为其生成存储static const int.您不能获取an的地址,enum编译器将永远不会为其生成存储.
另请参见模板元编程 - 使用Enum Hack和静态Const之间的区别