這是代碼: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_」 像什麼或在哪裏? –