[英]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.