[英]What caused the following aggregate initialization problem?
我正在尝试重现有关学习 c++ 的教科书中解释的代码。 最简单的一种如下。 但它没有按预期编译。
#include<vector>
using namespace std;
struct Storage
{
vector<int> data;
};
Storage GetStorage(vector<int> params)
{
return Storage{ .data=params};
}
Intellisense 给了我这个错误:
Storege{(<error-type>)<error-constant>}
expected an expression C/C++(29)
您必须将语言版本设置为 C++20 才能使指定的初始化程序起作用。 在 Visual Studio 上,您必须在其他编译器上启用标志/std:c++latest
和-std=c++20
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.