考虑一下代码:
struct Foo
{
const char str[] = "test";
};
int main()
{
Foo foo;
}
Run Code Online (Sandbox Code Playgroud)
它无法使用g ++和clang ++编译,基本上吐出来
error: array bound cannot be deduced from an in-class initializer
我明白这是标准可能会说的,但有什么特别好的理由吗?由于我们有一个字符串文字,似乎编译器应该能够毫无问题地推断出大小,类似于简单地声明一个类外const的类似C的空终止字符串的情况.