I just stumbled upon this same problem. The code we are discussing is part of the implementation of KIT shrinking hierarchies .
This is the only compilation error when trying to compile code with gcc 4.8.
The fix suggested by @vitaut is what is needed to complete this work. However, note that the following lines already exist in main.cpp:
If you decide to create the EliminationWeight.cpp file to go along with your EliminationWeight.h and include it in the Makefile, these lines cause you to see a different error than mentioned above:
main.cpp:86:31: error: uninitialized const 'EliminationWeight::MAX_VALUE' [-fpermissive] const EliminationWeight::Type EliminationWeight::MAX_VALUE; ^ main.cpp:87:31: error: uninitialized const 'EliminationWeight::MIN_VALUE' [-fpermissive] const EliminationWeight::Type EliminationWeight::MIN_VALUE; ^
The solution is to either delete these lines in main.cpp, or use them for actual initialization. I went with the latter and now the lines look like this:
const EliminationWeight::Type EliminationWeight::MAX_VALUE = std::numeric_limits< EliminationWeight::Type >::max(); const EliminationWeight::Type EliminationWeight::MIN_VALUE = -std::numeric_limits< EliminationWeight::Type >::max();
Note that I used the std::numeric_limits pattern for the type defined by EliminationWeight::Type typedef. This means that we need to change only this typedef type to use a different type.
However, using them in main.cpp, we include the header for the numeric_limits template. It also worked for me without including a header, but this is probably because it is included through some other file. For clean code purposes, we should include it anyway.
#include <limits>
Also note that C ++ 11 provides a new lowest function for the numeric_limits template, which means you can replace the last line as follows:
const EliminationWeight::Type EliminationWeight::MIN_VALUE = std::numeric_limits< EliminationWeight::Type >::lowest();
However, C ++ reference to lowest indicates the return value for floating point types as
Depends on implementation; usually negative of max ()
so I'm not sure how much you win using this feature. This gives you cleaner code, but it seems that the return value is somewhat unspecified.