Q:

VS2010 only static const integral data members can be initialized within a class

I've recently been told that Windows Visual Studio is one of the best IDEs for C++ development, so I decided to get it, but it's my first time using it and I'm already getting a weird error. The following code:
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;

class Player {
public:
    string name = "Player";
};

int main() {
    cout << "Works";
    return 0;
}

returns error C2864: 'Player::name' : only static const integral data members can be initialized within a class. What is wrong? This code compiled in Codeblocks IDE. Please explain to me what is wrong I don't understand.

A:

In C++03, you cannot initialize the data member at the point of declaration. You can do it in the constructor(s).
class Player {
public:
    Player() : name("Player") {}
    string name;
};

In C++11, your code is fine, so it could be that you were compiling with C++11 support in Codeblocks.

A:

class Player {
public:
    string name = "Player";
};

This syntax has been introduced in C++11. In previous versions of standard, as C++03, that is supported by MSVC, this should look like this:
class Player {
public:
    Player() : name("Player") {}
    string name;
};

