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';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.