Posted By

DrPepper on 09/24/11


Tagged


Versions (?)

[CISP 430] enum


 / Published in: C++
 

Example of enum with using template class

  1. template <int N>
  2. struct Factorial
  3. {
  4. enum { value = N * Factorial<N - 1>::value };
  5. };
  6.  
  7. template <>
  8. struct Factorial<0>
  9. {
  10. enum { value = 1 };
  11. };
  12.  
  13. // Factorial<4>::value == 24
  14. // Factorial<0>::value == 1
  15. void foo()
  16. {
  17. int x = Factorial<4>::value; // == 24
  18. int y = Factorial<0>::value; // == 1
  19. }

Report this snippet  

You need to login to post a comment.