c++ - Assigning to a static const member a value coming from a function (from a static method, to be more precise) -


the following not allowed ('std::numeric_limits::max()' cannot appear in constant-expression):

#include <limits>     struct mystruct {  private:     static const unsigned int invalid_value = std::numeric_limits<unsigned int>::max();  public:   unsigned int index;    inline mystruct() : index(invalid_value) {} }; 

which best way obtain desired behaviour? like, if possible, have invalid_value known @ compile time (e.g. allow compiler doing better optimization).

how define constant ~0u. since unsigned int defined "direct binary representation", inverse thereof should bits set.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -