Fro*_*art 2 c++ arrays new-operator language-lawyer
以下结构是否符合C++标准,以及在此声明之后我可以使用arr做什么?
char* arr = new char[];
Run Code Online (Sandbox Code Playgroud)
提前致谢.
不,这是不允许的.[expr.new]/1中new-expression的语法指定
noptr-new-declarator:
[expression]attribute-specifier-seq opt
noptr-new-declarator [ constant-expression ] attribute-specifier-seq opt
显然,代码中的括号之间没有表达.它也没有意义:你怎么能分配一个未知长度的数组?
如果需要一个动态更改大小的数组,请使用std::vector.