Thursday, April 9, 2015

How do I define an in-class constant?

If you want a constant that you can use in a compile time constant expression, say as an array bound, use constexpr if your compiler supports that C++11 feature, otherwise you have two other choices:

You have more flexibility if the constant isn’t needed for use in a compile time constant expression:

You can take the address of a static member if (and only if) it has an out-of-class definition:

No comments:

Post a Comment