Exposing Static Constant With Boost
Solution 1:
In addition to being declared, static
data members must also be defined.
// ExposureSinusoid.hclassExposureSinusoid
{
// ...public:
staticconst UINT _min_exp = 20; // declaration// ...
};
// ExposureSinusoid.cppconst UINT ExposureSinusoid::_min_exp; // definition
The only scenario where the definition of a static
data member may be omitted is when the data member in question is a const
fundamental integral type, and it is initialized with a constant expression, and it is never ODR-used (see the C++03 standard, §9.4.2/4); however, taking the address of a variable qualifies as ODR-usage, so in your case a definition must be supplied.
Solution 2:
Static linkage means that the symbol is not visible outside the TU! Change static
to extern
(because global constants are implicitly static):
externconstUINT _min_exp = 20;
Correction: I didn't see that _min_exp
was a member variable, apologies. In that case the answer is, as ildjarn already said, to add the definition of the variable outside the class definition. To be sure, both the declaration and the initialization go inside, but the definition goes outside:
structFoo {
staticconstint a = 1; // initialization can go inside the class definition
};
constint Foo::a; // definition (this is what the linker sees)
Post a Comment for "Exposing Static Constant With Boost"