Jump to content
  • Advertisement
Sign in to follow this  
akaitora

static member variables in c++

This topic is 2840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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"

Share this post


Link to post
Share on other sites
Try


class CBlah
{
public:

static const int iA = 1; // Works
static 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"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!