C++ standard for defining public variable static const integer -


Where I define a static constant integer in member variable c ++, in the header file where the class is defined or CPP File?

It complies with both conditions, if I put the definition inside the header file and if I take the definition in the CPP file, but is the C ++ standard?

Here is a complete quote from the C ++ standard about static static members: < Blockquote>

If the non-volatile constant static data member is an integral or calculated type, its declaration in the definition of a class can specify a brace-or-similar-prefix, in which each initial-segment that has an assignment expression, a There is constant expression (5.1 9). A static data member of the literal type can be declared in the class definition with the constexpr specifier; If so, its declaration will specify a brace-or-sum-initiator in which each initial-segment that is an assignment-expression is a constant expression. [Note: In both of these cases, the member can appear in continuous expression. Note of an end] The member will still be defined in a namespace area if this program is used in OD (3.2) and the namespace scope definition will not be the beginning .

So if a static static member is not ODR then its definition is not required outside the class

Note: In this context, the way in which it is unimportant Fixed static members are public or not.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -