My understanding is that C ++ allows you to define constant members in a class if it is an integer type.
You seem to be right. You can initialize static constant integrals in a class declaration, but this is not a definition.
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr038.htm
Interestingly, if I comment on the call to std :: min, the code compiles and the links are just fine (even if test :: N is also mentioned in the previous line).
Any idea on what's going on?
std :: min takes its parameters by reference const. If they took them at a cost, you would not have this problem, but since you need a link, you also need a definition.
Here is the chapter / verse:
9.4.2 / 4 - If a static data member is of type const integer or const enumeration, its declaration in the class definition may indicate the initializer constant, which should be an integral constant expression (5.19). In this case, the term can appear in integral constant expressions. A member still needs to be defined in the namespace area, if used in the program, and the namespace area definition should not contain an initializer .
See Chu's answer for a possible workaround.
Crazy Eddie Jun 11 '10 at 20:36
source share