Problem with numeric_limits
Why this doesn't work?
enum : long {MaxValue = std::numeric_limits<long int>::max()};
I'm getting erro开发者_开发技巧r :Error 1 error C2057: expected constant expression
What isn't constant about it? Limits of long int are known at compile time so what's the problem?The problem is that although std::numeric_limits<long int>::max()
function returns constant value it is called in run-time and you need constant value in compile-time
Probably you can just use LONG_MAX
value instead (see climits header)?
As the other have said, you need a constant expression (functions don't qualify). Eventually C++1x will support a wider range of constant expressions, including functions. See n2235 and Bjarne Stroustrup's FAQ entry.
Yes, but a function cannot be executed at compile time. max()
精彩评论