Wednesday, 15 May 2013

One member enums in C++ -



One member enums in C++ -

this question has reply here:

static const fellow member value vs. fellow member enum : method improve & why? 7 answers

i stumbled upon reply question powers of integers in c++: http://stackoverflow.com/a/1506856/5363

i lot, don't quite understand why author uses 1 element enums opposed integer type explicitly. explain?

afaik has older compilers not allowing define compile-time constant fellow member data. c++11 do

template<int x, int p> struct pow { static constexpr int result = x*pow<x,p-1>::result; }; template<int x> struct pow<x,0> { static constexpr int result = 1; }; template<int x> struct pow<x,1> { static constexpr int result = x; }; int main() { std::cout << "pow(3,7) " << pow<3,7>::result << std::endl; homecoming 0; }

c++ enums

No comments:

Post a Comment