static member variables in c++
In order to initialize a static member variable, why must the variable type be an integral type? Why can't we use say... floats? What's the deal here? I am using Visual Studio 2008. Thanks!
class CBlah
{
public:
static const int iA = 1; // Works
static const float fB = 1.0f; // Doesn't Work
};
The Error:
"error C2864: 'CBlah::fB' : only static const integral data members can be initialized within a class"
{
public:
static const int iA = 1; // Works
static const float fB = 1.0f; // Doesn't Work
};
The Error:
"error C2864: 'CBlah::fB' : only static const integral data members can be initialized within a class"
Try
[edit]
Keyword in the error message was within -
"error C2864: 'CBlah::fB' : only static const integral data members can be initialized within a class"
class CBlah{public:static const int iA = 1; // Worksstatic const float fB;};float CBlah::fB = 1.0f;
[edit]
Keyword in the error message was within -
"error C2864: 'CBlah::fB' : only static const integral data members can be initialized within a class"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement