Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with numeric_limits

Tags:

c++

numeric

Why this doesn't work?

enum : long {MaxValue = std::numeric_limits<long int>::max()};

I'm getting error :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?

like image 738
There is nothing we can do Avatar asked Nov 24 '10 12:11

There is nothing we can do


1 Answers

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

like image 193
Vladimir Avatar answered Oct 01 '22 23:10

Vladimir