Const data members must be initialized either via an initializer list in the constructor or with in-class initialization (C++11 and later). Since class A has no constructor and const member k is not initialized at declaration, the code fails to compile.