class A {
static const float B;
}
How do I initialize B?
How do I initialize a static const?
in A''s constructor initializer list? (What is a better name for that?)
A::A() : B(15) { blah; }
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.
you can initialize static constants with:
static variables (non-const) have to be initialized like fractoid said.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement