static member variables in c++

Started by
3 comments, last by rip-off 13 years, 4 months ago
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!

xdpixel.com - Practical Computer Graphics

Advertisement
How are you initializing the static member variable (might want to show some code)?

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

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"

xdpixel.com - Practical Computer Graphics

Try

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"

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

Because thus sayeth the standard, apparently.

This topic is closed to new replies.

Advertisement