So, I\'m aware that in C++ static members can be initialized inside the class if they are a const literal type like the following
class test{
public:
C++17 inline
variables
In C++17 if you also mark the static member as inline
, then I believe that you can odr-use it freely or have multiple definitions across compilation units, e.g.:
#include
class MyClass {
public:
inline static constexpr int i = 42;
};
int main() {
const int &cs = MyClass::i;
std::cout << cs << std::endl;
std::cout << &MyClass::i << std::endl;
}
More info at: How do inline variables work?