<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: Should structs Have Constructors in C++	</title>
	<atom:link href="https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Sun, 10 Feb 2019 05:38:45 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1070</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 13:09:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1070</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1069&quot;&gt;chris&lt;/a&gt;.

It&#039;s certainly changed at some point. Doh!! In MS VS2017 default values don&#039;t deactivate aggregate initializations. You think you know the rules - then puff, they are changed. You just can&#039;t keep up.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1069">chris</a>.</p>
<p>It&#8217;s certainly changed at some point. Doh!! In MS VS2017 default values don&#8217;t deactivate aggregate initializations. You think you know the rules &#8211; then puff, they are changed. You just can&#8217;t keep up.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: chris		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1069</link>

		<dc:creator><![CDATA[chris]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 12:48:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1069</guid>

					<description><![CDATA[&quot;And, like “real” constructors, their presence (even if for only one attribute) deactivates aggregate initialization.&quot;
I think this was changed in c++14. Default values no longer deactivate aggregate initializations.]]></description>
			<content:encoded><![CDATA[<p>&#8220;And, like “real” constructors, their presence (even if for only one attribute) deactivates aggregate initialization.&#8221;<br />
I think this was changed in c++14. Default values no longer deactivate aggregate initializations.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1068</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 11:30:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1068</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1064&quot;&gt;jft&lt;/a&gt;.

Yes I meant private. Fixed now, thanks!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1064">jft</a>.</p>
<p>Yes I meant private. Fixed now, thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tomas Dittmann (Chaosmeister)		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1067</link>

		<dc:creator><![CDATA[Tomas Dittmann (Chaosmeister)]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 10:54:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1067</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1061&quot;&gt;Miguel Raggi&lt;/a&gt;.

https://stackoverflow.com/questions/24550924/emplacement-of-a-vector-with-initializer-list

you need to be explicit - however this does not really emplace it anymore.

#include 
#include 

struct Point
{
int x;
int y;
};

int main()
{
    std::vector A;
    A.emplace_back(Point{2,2});

    return 0;
}]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1061">Miguel Raggi</a>.</p>
<p><a href="https://stackoverflow.com/questions/24550924/emplacement-of-a-vector-with-initializer-list" rel="nofollow ugc">https://stackoverflow.com/questions/24550924/emplacement-of-a-vector-with-initializer-list</a></p>
<p>you need to be explicit &#8211; however this does not really emplace it anymore.</p>
<p>#include<br />
#include </p>
<p>struct Point<br />
{<br />
int x;<br />
int y;<br />
};</p>
<p>int main()<br />
{<br />
    std::vector A;<br />
    A.emplace_back(Point{2,2});</p>
<p>    return 0;<br />
}</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1066</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 10:01:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1066</guid>

					<description><![CDATA[On a slight tangent, There is Designated Initialization coming in c++20 - an idea taken from c99. But why have the Working Group decided to cripple it at birth by disallowing the &#039;good&#039; bits from c - such as designators in c can be in any order but in c++20 can only be in the declaration order of the data members? Why should the user of a struct have to know the order of its data members?]]></description>
			<content:encoded><![CDATA[<p>On a slight tangent, There is Designated Initialization coming in c++20 &#8211; an idea taken from c99. But why have the Working Group decided to cripple it at birth by disallowing the &#8216;good&#8217; bits from c &#8211; such as designators in c can be in any order but in c++20 can only be in the declaration order of the data members? Why should the user of a struct have to know the order of its data members?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1065</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 09:34:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1065</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1061&quot;&gt;Miguel Raggi&lt;/a&gt;.

That&#039;s why we tend to use Member Initialization, default constructor and constructor. So we loose Aggregate Initialization. We consider the benefits of having constructors outweigh this small (to us) downside.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1061">Miguel Raggi</a>.</p>
<p>That&#8217;s why we tend to use Member Initialization, default constructor and constructor. So we loose Aggregate Initialization. We consider the benefits of having constructors outweigh this small (to us) downside.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1064</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 08:33:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1064</guid>

					<description><![CDATA[&quot;by making the data public and access it with getters&quot;

If the data is public, why use getters??? Do you mean data private?]]></description>
			<content:encoded><![CDATA[<p>&#8220;by making the data public and access it with getters&#8221;</p>
<p>If the data is public, why use getters??? Do you mean data private?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Benjamin Navarro		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1063</link>

		<dc:creator><![CDATA[Benjamin Navarro]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 06:58:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1063</guid>

					<description><![CDATA[You could also use designators to identify which field of the struct you want to initialize. Small example here: http://cpp.sh/2itke]]></description>
			<content:encoded><![CDATA[<p>You could also use designators to identify which field of the struct you want to initialize. Small example here: <a href="http://cpp.sh/2itke" rel="nofollow ugc">http://cpp.sh/2itke</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Vincent Zalzal		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1062</link>

		<dc:creator><![CDATA[Vincent Zalzal]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 03:32:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1062</guid>

					<description><![CDATA[I used to create constructors for my structs, but nowadays, I practically never do anymore. As you said, if obvious (which is often the case), I prefer aggregate initialization. If not obvious or if it requires interacting with other objects, I go for the external factory method. I find it cleaner to see the struct as pure data and not mix it with code interacting with other objects. Also, the factory method allows you to use an expressive name. Finally, a downside of using a constructor with arguments is that it disables the default constructor. You almost always need to add it back (using =default).

Also, when not too cumbersome, I prefer the terse version of makeMyLocalData because RVO is now guaranteed in C++17, which is not the case of NRVO (even if it is highly likely). Also in C++17, the terse version would allow to return a non-copyable, non-movable struct, if you are in that edge case (e.g. your struct contains a mutex).]]></description>
			<content:encoded><![CDATA[<p>I used to create constructors for my structs, but nowadays, I practically never do anymore. As you said, if obvious (which is often the case), I prefer aggregate initialization. If not obvious or if it requires interacting with other objects, I go for the external factory method. I find it cleaner to see the struct as pure data and not mix it with code interacting with other objects. Also, the factory method allows you to use an expressive name. Finally, a downside of using a constructor with arguments is that it disables the default constructor. You almost always need to add it back (using =default).</p>
<p>Also, when not too cumbersome, I prefer the terse version of makeMyLocalData because RVO is now guaranteed in C++17, which is not the case of NRVO (even if it is highly likely). Also in C++17, the terse version would allow to return a non-copyable, non-movable struct, if you are in that edge case (e.g. your struct contains a mutex).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/06/15/should-structs-have-constructors-in-cpp/#comment-1061</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 03:21:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3562#comment-1061</guid>

					<description><![CDATA[There is a problem with aggregate initialization. This doesn&#039;t work:
struct Point
{
    int x;
    int y;
};

// ...

std::vector A;
A.emplace_back({2,2});

Is there any solution to this? I know I can do push_back, but this just hides the problem... If I do define a constructor for Point, I can then do A.emplace_back(3,5) and this adds point (3,5), as expected.]]></description>
			<content:encoded><![CDATA[<p>There is a problem with aggregate initialization. This doesn&#8217;t work:<br />
struct Point<br />
{<br />
    int x;<br />
    int y;<br />
};</p>
<p>// &#8230;</p>
<p>std::vector A;<br />
A.emplace_back({2,2});</p>
<p>Is there any solution to this? I know I can do push_back, but this just hides the problem&#8230; If I do define a constructor for Point, I can then do A.emplace_back(3,5) and this adds point (3,5), as expected.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
