<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>constructors | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/constructors/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Wed, 22 Apr 2020 11:20:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>constructors | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>A small C++ Tip. Return values from Constructors</title>
		<link>https://learncgames.com/a-small-c-tip-return-values-from-constructors/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-small-c-tip-return-values-from-constructors</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 29 Apr 2020 23:00:15 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[constructors]]></category>
		<category><![CDATA[references]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=483</guid>

					<description><![CDATA[<p>You can&#8217;t return anything from a constructor.  One way is to use exceptions but those can bring their own issues. Google&#8217;s C++ guidelines actually stipulate no exceptions and I&#8217;ve heard it from others as well that they prefer not to use them. Some people avoid it by having a mostly empty constructor and then an [&#8230;]</p>
The post <a href="https://learncgames.com/a-small-c-tip-return-values-from-constructors/">A small C++ Tip. Return values from Constructors</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignleft size-thumbnail wp-image-376" src="https://learncgames.com/wp-content/uploads/2020/04/cLogo-150x150.png" alt="C++ Logo" width="150" height="150" />You can&#8217;t return anything from a constructor.  One way is to use exceptions but those can bring their own issues. Google&#8217;s C++ guidelines actually stipulate no exceptions and I&#8217;ve heard it from others as well that they prefer not to use them. Some people avoid it by having a mostly empty constructor and then an init() method to do the real initialisation and return a success/fail state.</p>
<p>But there is a simple trick that you can use, just return the state as a reference. Here&#8217;s an example. If you want to return more values, use a struct.</p>
<pre><code class="language-cpp" data-line="">#include &lt;iostream&gt;
using namespace std;

class Simple {
public:

    Simple(bool&amp; failure) {
        failure = true;
    }

    ~Simple() {
    }
};

int main() {

    bool fail_flag = false;
    Simple f(fail_flag);
    if (fail_flag)
        cout &lt;&lt; &quot;failed &quot; &lt;&lt; endl;
    else
        cout &lt;&lt; &quot;Success&quot; &lt;&lt; endl;
}</code></pre>The post <a href="https://learncgames.com/a-small-c-tip-return-values-from-constructors/">A small C++ Tip. Return values from Constructors</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">483</post-id>	</item>
	</channel>
</rss>
