为了你的使用operator""s而std::string必须这样做using namespace std::string_literals.但是不_保留用户定义的文字是保留的,因此可能的冲突不能成为借口.另一个operator""s来自std::chrono但是那是int文字,所以也没有冲突.
这是什么原因?
这是允许的:
int a[]{1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
但不是这个:
auto a = new int[]{1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
您必须指定边界.为什么?
编辑:正确的语法(不编译)是:
auto a = new (int[]){1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
这给出了真正的错误消息,即:
error: invalid use of array with unspecified bounds
Run Code Online (Sandbox Code Playgroud)