Why initilizing static const string member is not possible in class body

Viewed 4423

I am using c++ 14. I need to use static const string in my class. But when I write

class myClass
{
     static constexpr const std::string S="aa";
}

it doesn't compile. The result from compiler(g++) is

type 'const string {aka const std::__cxx11::basic_string<char>}' of constexpr variable 'S::S' is not literal

If I write it with char pointer like:

class myClass
{
     static constexpr const *char S="aa";
}

it is compiled.

I know that string can be initialized outside class. My question is why 1-st variant is not compiled, second does. I would like to know what standard say.

1 Answers
Related