Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

The C modest god

How do I initialize a static const?

This topic is 5310 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

Advertisement
quote:
Original post by fractoid
in A''s constructor initializer list? (What is a better name for that?)

A::A() : B(15) { blah; }


I forgot to mention that B is in public.
But B is static, therfore it is not related to instance and cannot be initialized with a constructor.

Share this post


Link to post
Share on other sites
you can initialize static constants with:

static const float B = 1.0;


static variables (non-const) have to be initialized like fractoid said.

Share this post


Link to post
Share on other sites
quote:
Original post by fractoid
in A''s constructor initializer list? (What is a better name for that?)

A::A() : B(15) { blah; }


Nope, thankyou for playing. Anyway, you just put

float A::B = 1.0f;

in you cpp file, and it will work. That''s how you have to do any type of static in a class at first.

Share this post


Link to post
Share on other sites

  • 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!