How do I initialize a static const?

Started by
4 comments, last by The C modest god 20 years, 1 month ago
I have the following code: class A { static const float B; } How do I initialize B?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
in A''s constructor initializer list? (What is a better name for that?)

A::A() : B(15) { blah; }
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.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
you can initialize static constants with:
static const float B = 1.0; 


static variables (non-const) have to be initialized like fractoid said.
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.
Ooops, missed the ''static'' bit (d''oh!)

yeah, what Puzzler said.

This topic is closed to new replies.

Advertisement