Isn't it okay to initialize the static const
member variable within the class?
The error message says to initialize out of line.
I don't want to use #define
but what should I do
Static data member of type 'const string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') must be initialized out of line member
class A {
private:
static const string RECTANGLE = "rectangle";
}
static const
If a member variable can be initialized within the class
It is only possible for .
If you ask, it should be initialized outside of the class because it is string
.
yourheader.h)
class A {
private:
static const string RECTANGLE;
};
yoursource.c)
const string A::RECTANGLE = "rectangle";
© 2024 OneMinuteCode. All rights reserved.