i got compiler error stating that :

Only static data members with const integral or const enumeration type can specify an initializer in the class definition

what is the logic behind that? why is the compiler designed not to accept any non constant static initialization of types?

>why is the compiler designed not to accept
>any non constant static initialization of types?
You can (technically) initialize static data members with non-constant values, just not directly within the class definition:

#include <cstdlib>
#include <iostream>

class foo {
public:
  static int x;
};

int foo::x = rand();

int main()
{
  std::cout<< foo::x <<'\n';
}