簡體   English   中英

是什么導致了以下聚合初始化問題?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM