Code:
#include <iostream >
using namespace std;

class CL
{
      public:
             int x;
           static int y;
};
int CL :: y=2;

int main()
{

return 0;
}
Why I can't write it like?

Code:
#include <iostream >
using namespace std;

class CL
{
      public:
             int x;
           static int y=2;
};


int main()
{

return 0;
}

And why in local classes (like class declared in function) I can't use static variables?

Thanks in advance.