5

Possible Duplicate:
Template Metaprogramming - Difference Between Using Enum Hack and Static Const

please explain what for is enum used in following implementation of 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 enum in this case?

Community
  • 1
  • 1
user1494506
  • 1,283
  • 1
  • 12
  • 9

1 Answers1

6

There could be a difference if you ever try to take an address of an static const int. In that case, the compiler will generate storage for the static const int. You can't take the address of an enum and the compiler will never generate storage for it.

See also Template Metaprogramming - Difference Between Using Enum Hack and Static Const

Community
  • 1
  • 1
TemplateRex
  • 69,038
  • 19
  • 164
  • 304