Dies ist der Code:Visual Studio 2015 Zeichenfolgenliteral nicht immer konstant?
#include <iostream>
using namespace std;
struct ConstStr
{
char const* const Str;
constexpr struct ConstStr(char const* str) :Str(str) {}
};
struct Container {
static constexpr struct ConstStr hey{ "hey" };
};
struct StructScope1
{
struct ConstStr {
char const* const Str;
constexpr ConstStr(char const* str) :Str(str) {}
};
struct Container {
static constexpr StructScope1::ConstStr hey{ "hey" };
};
};
struct StructScope2
{
struct Container {
static constexpr ConstStr hey{ "hey" };
};
};
struct Container2 {
static constexpr struct StructScope1::ConstStr hey { "hey" };
};
int main()
{
cout << "Hello World" << endl;
cout << "Container::hey.Str " << Container::hey.Str << endl;
cout << "StructScope1::Container::hey.Str " << StructScope1::Container::hey.Str << endl;
cout << "StructScope2::Container::hey.Str " << StructScope2::Container::hey.Str << endl;
cout << "Container2::hey.Str " << Container2::hey.Str << endl;
}
ich Visual Studio 2015. Aus irgendeinem Grund bin mit, schlägt die Erklärung/Initialisierung von StructScope1::Container::hey
zu kompilieren. Es gibt dem Fehler
Ausdruck einen konstanten Wert
Aber ich initialisieren den gleichen Code in anderen Orten haben muss, und es funktioniert gut. Ist das ein Compiler Bug, oder fehlt mir etwas?
"_in andere places_" Wie, was oder wo? –