<?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>enum class | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/enum-class/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:19:42 +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>enum class | 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>C++ enum class vs enum</title>
		<link>https://learncgames.com/c-enum-class-vs-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-enum-class-vs-enum</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 28 Apr 2020 23:00:12 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[enum class]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=481</guid>

					<description><![CDATA[<p>I&#8217;d read about enum class in C++. It&#8217;s a slight strengthening of the compiler checking compared to plain old enums.  Why you may wonder? Well, Conventional enums can implicitly convert to int, causing errors when someone does not want an enumeration to act as an integer. Conventional enums export their enumerators to the surrounding scope, [&#8230;]</p>
The post <a href="https://learncgames.com/c-enum-class-vs-enum/">C++ enum class vs enum</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:763,&quot;href&quot;:&quot;http:\/\/www.stroustrup.com\/C++11FAQ.html#enum&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;https:\/\/www.stroustrup.com\/C%20%2011FAQ.html&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignleft wp-image-376 size-thumbnail" src="https://learncgames.com/wp-content/uploads/2020/04/cLogo-150x150.png" alt="C++ Logo" width="150" height="150" />I&#8217;d read about<a title="LInk to enum class definition on C++ 11 FAQ" href="http://www.stroustrup.com/C++11FAQ.html#enum" target="_blank" rel="noopener noreferrer"> enum class</a> in C++. It&#8217;s a slight strengthening of the compiler checking compared to plain old enums.  Why you may wonder? Well,</p>
<ul>
<li>Conventional enums can implicitly convert to int, causing errors when someone does not want an enumeration to act as an integer.</li>
<li>Conventional enums export their enumerators to the surrounding scope, causing name space pollution.</li>
<li>The underlying type of an <code class="" data-line="">enum</code> cannot be specified, causing confusion, compatibility problems, and makes forward declaration impossible.</li>
</ul>
<p>Additionally you can declare the underlying storage type, which lets the compiler catch bugs where a value is too large for the storage. Here&#8217;s a made up example to show this:</p>
<pre><code class="language-cpp" data-line="">
enum class byteThings : unsigned char {
Thing1 = 0x01,
Thing2 = 0x02,
Thing3 = 0x04,
BigThing = 0x120  // Compiler will complain!
}</code></pre>
<p>The downside is that to get the int value, you now need to do a static cast but it does make your code safer.</p>
<pre><code class="language-cpp" data-line="">byteThings b = Thing2; 
int i= static_cast(thing); // 2</code></pre>
<p>&nbsp;</p>The post <a href="https://learncgames.com/c-enum-class-vs-enum/">C++ enum class vs enum</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">481</post-id>	</item>
	</channel>
</rss>
