1

I am trying to reproduce the code explained in a textbook about learning c++. The simplest one is given as follows. But it does not compile as expected.

#include<vector>

using namespace std;

struct Storage
{
 vector<int> data;
};

Storage GetStorage(vector<int> params)
{
    return Storage{ .data=params};
}

Intellisense gives me this error back:

Storege{(<error-type>)<error-constant>}
expected an expression C/C++(29)
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165

1 Answers1

2

You must set your language version to C++20 for designated initializers to work. On visual studio you must enable the flag /std:c++latest and -std=c++20 on other compilers

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141