开发者

Problem with numeric_limits

开发者 https://www.devze.com 2023-01-26 12:51 出处:网络
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

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()

0

精彩评论

暂无评论...
验证码 换一张
取 消