Implementing the pow (power) template from the wiki

Possible duplicate:
Template metaprogramming - Difference between using Enum Hack and Static Const

please explain what is enumused for the next implementation of the power template.

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;

I found it on Wikipedia. Is there a difference between int, and enumin this case?

+5
source share
1 answer

There may be a difference if you try to take the address static const int. In this case, the compiler will generate storage for static const int. You cannot take an address enum, and the compiler will never generate storage for it.

. - Enum Hack Static Const

+6

All Articles