Using numeric_limits::max() in constant expressions

前端 未结 5 848
無奈伤痛
無奈伤痛 2020-12-10 11:04

I would like to define inside a class a constant which value is the maximum possible int. Something like this:

class A
{
    ...
    static const int ERROR_V         


        
5条回答
  •  萌比男神i
    2020-12-10 11:29

    You want:

    #include 
    
    struct A {
    static const int ERROR_VALUE;
    }; 
    
    const int A::ERROR_VALUE = std::numeric_limits::max();
    

    Put the class/struct in a header and the definition in a .cpp file.

提交回复
热议问题