Exposing Static Constant With Boost
Solution 1:
In addition to being declared, static
data members must also be defined.
// ExposureSinusoid.h
class ExposureSinusoid
{
// ...
public:
static const UINT _min_exp = 20; // declaration
// ...
};
// ExposureSinusoid.cpp
const 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):
extern const UINT _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:
struct Foo {
static const int a = 1; // initialization can go inside the class definition
};
const int Foo::a; // definition (this is what the linker sees)
Post a Comment for "Exposing Static Constant With Boost"