c++ - 字符串文字边界数组新表达式第一维参数的示例

标签 c++ initialization c++14 string-literals

来自cppreference :

In the following cases the expression specifying the first dimension is erroneous:

  • the value is smaller than the number of array elements provided in the brace-enclosed initializer (including the terminating \0 on a string literal).

有人可以提供一个示例,说明字符串文字太长以至于它限制了数组新表达式的第一个维度吗?

我似乎想不出一个:(

我看到的唯一有点相似的东西是类似 auto p1 = new char[1][5]{"xyz"}; 的东西。但这与第一个维度无关。

最佳答案

类似这样的事情:

new const char[2]{"this is way more than one character"};

请注意,gcc 甚至不编译 new const char[2]{"x"},但这是一个正交问题。

关于c++ - 字符串文字边界数组新表达式第一维参数的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49679114/

相关文章:

c++ - 传递可变参数时保留引用

c++ - `decltype` 是给我一个对象的静态类型,还是它的运行时类型?

c++ - thread_local 变量初始化

c++ - 局部变量的静态初始化

c++ - 通用统一初始化 : `double` to `int`

c++ - 实现类似的类

c++ - 谷歌模拟 : How to configure custom message to explain match failure

java - 在 switch 语句中初始化新文件

c++ - 构造许多嵌套的类成员

c++ - 为什么对于具有多个返回路径的 lambda 返回 lambda 会出现类型推导错误?