Static variables aren’t bound to an instance, so can’t be set in the constructor initialisation list.
You’d set the default value where you define (the header contains the declaration) the static variable (typically inside the cpp file of the class containing it), eg)
Hi I am trying to create a static integer in a class but I am getting errors on declaring it.
I can’t initialize it in the constructor of the class.
.h file
static int32 NumberOfProjectiles;
It shows the error
1>d:\ue4\new folder\myproject\source\myproject\ShotgunProjectile.h(31): error C2864: ‘AShotgunProjectile::NumberOfProjectiles’ : a static data member with an in-class initializer must have non-volatile const integral typeD:\ue4\New folder\MyProject\Source\MyProject\ShotgunProjectile.h(31) : error C2864: ‘AShotgunProjectile::NumberOfProjectiles’ : a static data member with an in-class initializer must have non-volatile const integral type