Jump to content
  • Advertisement
ePitts

needs at least "/std:c++latest"

Recommended Posts

Hi

with the code below I get initialiser needs at least  "/std:c++latest" or alike.

How to do that with VC community?

Thanks

 

static librain_glass_t windShield = {
    .slant_factor = 1.0,
    .thrust_point = tp,
    .therm_inertia = 20.0,
    .cabin_temp = 22.0
};

Share this post


Link to post
Share on other sites
Advertisement

"C++ designated initializers only available with -std=c++2a or -std=gnu++2a [-Wpedantic]"

static librain_glass_t windShield{ 1.0, tp, 20.0, 22.0 };

Share this post


Link to post
Share on other sites
Posted (edited)

I have no idea, i use eclipse cdt (or the commandline).

Somewhere in the compiler settings i'd assume, close to where you set debug/optimizing etc., or where you can manually type in compiler options.

But C++20 isn't ready yet. Use the direct initializer. It is faster than all the assignments anyway.

Edited by Green_Baron

Share this post


Link to post
Share on other sites

For VS, the setting you are looking for is in the project properties, under "C/C++/Language/C++ language standard".

 

40 minutes ago, Green_Baron said:

But C++20 isn't ready yet. Use the direct initializer. It is faster than all the assignments anyway. 

Huh? Designated initializer is not an assignment though, you just specify which members you initialize, instead of having to fill in every one in order.

 

Share this post


Link to post
Share on other sites
34 minutes ago, Green_Baron said:

You may be right. I must admit, to me it is a little unclear when, where, how and which direct/copy/whatever initialization is, was or will be called.

https://en.cppreference.com/w/cpp/language/aggregate_initialization. Looks like it is copy-initialization. But i am unsure ... ? 

Yeah, that standard is a bit vague about it, remember we're talking about C++, which has the philosophy of "zero overhead abstraction". It would be very suprising the in order to be able to do this:

struct Foo
{
   std::string x;
   std::string y;
   std::string z;
}

Foo foo {L"", L"", L"Hello"); // before
Foo foo {.z = L"Hello"); // after

we'd now have to pay the cost of an additional default-ctor followed by an assignment. (Not saying its not possible though, see initializer list ie., so importantly I made a test myself:

struct Y
{
	Y(void)
	{
		std::cout << "Default ctor";
	}

	Y(int x)
	{
		std::cout << "Value ctor";
	}
};

struct X
{
	Y str;
};

X x{ .str = 1 };

This will call the Y(int) ctor, so everything is working as expected (tested in VS in debug build, so not an optimizer-thing but standard behaviour.

Share this post


Link to post
Share on other sites
Posted (edited)

[snip] That was nonsense from my side because i was too quick ...

Both aggregate and direct initialization call the constructor on my machine. You were right.

Now  i will make a break. I've been here too long :-)

Edited by Green_Baron

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!