这是代码:Visual Studio 2015字符串文字不总是不变?
#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;
}
我使用Visual Studio 2015对于一些原因,StructScope1::Container::hey
声明/初始化失败编译。它给出了错误
表达必须有一个恒定的值
但我在其他地方初始化相同的代码,它工作得很好。这是一个编译器错误,还是我错过了什么?
“_in其他places_” 像什么或在哪里? –