What is the correct way to initialize static data members in C++ (98, 11 and 14)

The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be initialised in class with a constant expression. A constexpr SDM must be initialised in class with a constant expression. C++17 no longer requires an initializer when the default constructor initialises every member. Also, constexpr SDMs … Read more

g++ and clang++ different behaviour with recursive initialization of a static member

It is unspecified. Both compilers are right. Here are the relevant pieces from cppreference “initialization”. Static initialization For all other non-local static and thread-local variables, Zero initialization takes place So for all these variables, they are zero when the program loads. Then: Dynamic initialization After all static initialization is completed, dynamic initialization of non-local variables … Read more

Why aren’t static data members allowed in local classes?

From the standard section 9.4.2: If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression. In that case, the member can appear in integral constant expressions within its scope. The member shall still be defined … Read more

Weird undefined symbols of static constants inside a struct/class

Definition needed The code you have provided is non-standard. While you can provide initializers for const static int members directly in the class, you still need to provide separate definitions. It is weird, a kind of unexpected, but you are expected to write it like this: #include <algorithm> struct Foo { static const int A … Read more

Should I use std::string or const char* for string constants? [duplicate]

Usually you should prefer std::string over plain char pointers. Here, however, the char pointer initialized with the string literal has a significant benefit. There are two initializations for static data. The one is called static initialization, and the other is called dynamic initialization. For those objects that are initialized with constant expressions and that are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)