<?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/"
		>
<channel>
	<title>Comments on: 4.5 &#8212; Enumerated types</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/45-enumerated-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:20:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: kalvin</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-96897</link>
		<dc:creator>kalvin</dc:creator>
		<pubDate>Thu, 02 Feb 2012 00:33:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-96897</guid>
		<description>Enumerations are a little confusing for me. I would better understand them if i had a practical use for them.. I know that no arithmetic operations are allowed on enum, and that since enums are an ordered set of values, you can use relational operators, and loops. this being said I guess I can see how using enum to make your program more readable might be benificial. But to really incorperate enums into your program you will have to input and output enums indirectly as you can not directly output or input enumeration data types.. So for now , i think you have to choose whether to make your program more readable with more work using enumerations, or not and save the extra programming.. Idk maybe as i learn and play with this more i will find its practicality</description>
		<content:encoded><![CDATA[<p>Enumerations are a little confusing for me. I would better understand them if i had a practical use for them.. I know that no arithmetic operations are allowed on enum, and that since enums are an ordered set of values, you can use relational operators, and loops. this being said I guess I can see how using enum to make your program more readable might be benificial. But to really incorperate enums into your program you will have to input and output enums indirectly as you can not directly output or input enumeration data types.. So for now , i think you have to choose whether to make your program more readable with more work using enumerations, or not and save the extra programming.. Idk maybe as i learn and play with this more i will find its practicality</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zingmars</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-95494</link>
		<dc:creator>zingmars</dc:creator>
		<pubDate>Thu, 26 May 2011 15:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-95494</guid>
		<description>PLEASE avoid using system(&quot;PAUSE&quot;). use cin.get() or something but, please avoid using any system(&quot;&quot;) function. That way you&#039;ll be doing favors both for yourself AND others who&#039;re reading your code.</description>
		<content:encoded><![CDATA[<p>PLEASE avoid using system(&#8220;PAUSE&#8221;). use cin.get() or something but, please avoid using any system(&#8220;&#8221;) function. That way you&#8217;ll be doing favors both for yourself AND others who&#8217;re reading your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: christopher11</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-95483</link>
		<dc:creator>christopher11</dc:creator>
		<pubDate>Tue, 24 May 2011 02:49:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-95483</guid>
		<description>This is what i came up with
#include
using namespace std;

enum Race
{
     RACE_ORC = 1,
     RACE_GOBLIN = 2,
     RACE_TROLL = 3,
     RACE_OGRE = 4
};

int pickRace(int race);

main()
{
      int x;
      cout&lt;&lt; &quot;Choose your race: &quot; &lt;&lt; endl &lt;&lt; &quot;Orc(1) - Goblin(2) - Troll(3) - Ogre(4)&quot;;
      cout&lt;&gt; x;
      pickRace(x);
      system(&quot;PAUSE&quot;);
      return 0;
}

int pickRace(int race)
{
     static int choice;
    if(race==1)
    {
               choice = RACE_ORC;
    }
    if(race==2)
    {
               choice = RACE_GOBLIN;
    }
    if(race==3)
    {
               choice = RACE_TROLL;
    }
    if(race==4)
    {
               choice = RACE_OGRE;
    }
    
    if(choice==1)
    {
                 cout&lt;&lt;&quot;You picked Orc.&quot;;
    }
    if(choice==2)
    {
                 cout&lt;&lt;&quot;You picked Goblin.&quot;;
    }
    if(choice==3)
    {
                 cout&lt;&lt;&quot;You picked Troll.&quot;;
    }
    if(choice==4)
    {
                 cout&lt;&lt;&quot;You picked Ogre.&quot;;
    }
    cout&lt;&lt; endl;
}</description>
		<content:encoded><![CDATA[<p>This is what i came up with<br />
#include<br />
using namespace std;</p>
<p>enum Race<br />
{<br />
     RACE_ORC = 1,<br />
     RACE_GOBLIN = 2,<br />
     RACE_TROLL = 3,<br />
     RACE_OGRE = 4<br />
};</p>
<p>int pickRace(int race);</p>
<p>main()<br />
{<br />
      int x;<br />
      cout&lt;&lt; &quot;Choose your race: &quot; &lt;&lt; endl &lt;&lt; &quot;Orc(1) &#8211; Goblin(2) &#8211; Troll(3) &#8211; Ogre(4)&quot;;<br />
      cout&lt;&gt; x;<br />
      pickRace(x);<br />
      system(&#8220;PAUSE&#8221;);<br />
      return 0;<br />
}</p>
<p>int pickRace(int race)<br />
{<br />
     static int choice;<br />
    if(race==1)<br />
    {<br />
               choice = RACE_ORC;<br />
    }<br />
    if(race==2)<br />
    {<br />
               choice = RACE_GOBLIN;<br />
    }<br />
    if(race==3)<br />
    {<br />
               choice = RACE_TROLL;<br />
    }<br />
    if(race==4)<br />
    {<br />
               choice = RACE_OGRE;<br />
    }</p>
<p>    if(choice==1)<br />
    {<br />
                 cout&lt;&lt;&quot;You picked Orc.&quot;;<br />
    }<br />
    if(choice==2)<br />
    {<br />
                 cout&lt;&lt;&quot;You picked Goblin.&quot;;<br />
    }<br />
    if(choice==3)<br />
    {<br />
                 cout&lt;&lt;&quot;You picked Troll.&quot;;<br />
    }<br />
    if(choice==4)<br />
    {<br />
                 cout&lt;&lt;&quot;You picked Ogre.&quot;;<br />
    }<br />
    cout&lt;&lt; endl;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newUser</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-95322</link>
		<dc:creator>newUser</dc:creator>
		<pubDate>Wed, 13 Apr 2011 02:41:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-95322</guid>
		<description>If I had not read the comments I would have never noticed enum uses commas! May I suggest having it written in the tutorial too so it draws more attention to it?</description>
		<content:encoded><![CDATA[<p>If I had not read the comments I would have never noticed enum uses commas! May I suggest having it written in the tutorial too so it draws more attention to it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sm00th_0perat0r</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-95224</link>
		<dc:creator>sm00th_0perat0r</dc:creator>
		<pubDate>Tue, 01 Mar 2011 23:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-95224</guid>
		<description>&lt;pre&gt;I&#039;m pretty sure that by explicitly defined, he means setting it equal to a value yourself, as opposed to implicitly&lt;/br&gt;defined where the value would be chosen by its order in the list...&lt;/br&gt;&lt;/br&gt;...but I could be wrong!&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>I&#039;m pretty sure that by explicitly defined, he means setting it equal to a value yourself, as opposed to implicitly&lt;/br&gt;defined where the value would be chosen by its order in the list...&lt;/br&gt;&lt;/br&gt;...but I could be wrong!</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: SWEngineer</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-95118</link>
		<dc:creator>SWEngineer</dc:creator>
		<pubDate>Sat, 22 Jan 2011 11:59:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-95118</guid>
		<description>Simple well explained tutorial. Thanks.</description>
		<content:encoded><![CDATA[<p>Simple well explained tutorial. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bla</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-90037</link>
		<dc:creator>bla</dc:creator>
		<pubDate>Wed, 11 Aug 2010 10:48:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-90037</guid>
		<description>I am not really sure about the meaning of questions 3a,b. Does explicit mean explicit cast in this context?

&quot;3) True or false. Enumerators can be:
3a) explicitly assigned integer values&quot;
that would be:
&lt;pre&gt; Animal eAnimal = static_cast&lt;Animal&gt;(5); &lt;!--formatted--&gt;&lt;/pre&gt;
??

3b) not explicitly assigned a value
???</description>
		<content:encoded><![CDATA[<p>I am not really sure about the meaning of questions 3a,b. Does explicit mean explicit cast in this context?</p>
<p>&#8220;3) True or false. Enumerators can be:<br />
3a) explicitly assigned integer values&#8221;<br />
that would be:</p>
<pre> Animal eAnimal = static_cast&lt;Animal&gt;(5); <!--formatted--></pre>
<p>??</p>
<p>3b) not explicitly assigned a value<br />
???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luiwtf</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-89690</link>
		<dc:creator>Luiwtf</dc:creator>
		<pubDate>Thu, 05 Aug 2010 20:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-89690</guid>
		<description>&lt;pre&gt;if (part[BODY_PART] = 0 &amp;&amp; part[BODY_PART_FLAG] == 0)&lt;!--formatted--&gt;&lt;/pre&gt;

should be:

&lt;pre&gt;if (part[BODY_PART] == 0 &amp;&amp; part[BODY_PART_FLAG] == 0)&lt;!--formatted--&gt;&lt;/pre&gt;

note the 2 =&#039;s, instead of one :)

the reason it works with &#124;&#124; is because the second half comes up true as you have the == correct, as it is the first part is irrelevant.

edit - meh, just noticed it&#039;s a month old :D, i suck at remembering dates :p.</description>
		<content:encoded><![CDATA[<pre>if (part[BODY_PART] = 0 &amp;&amp; part[BODY_PART_FLAG] == 0)<!--formatted--></pre>
<p>should be:</p>
<pre>if (part[BODY_PART] == 0 &amp;&amp; part[BODY_PART_FLAG] == 0)<!--formatted--></pre>
<p>note the 2 =&#8217;s, instead of one :)</p>
<p>the reason it works with || is because the second half comes up true as you have the == correct, as it is the first part is irrelevant.</p>
<p>edit &#8211; meh, just noticed it&#8217;s a month old :D, i suck at remembering dates :p.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-88046</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 07 Jul 2010 16:23:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-88046</guid>
		<description>&lt;pre&gt;
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;

using namespace std;

namespace BODY_PARTS
{
    const int BPMEMBERS = 2;

    enum MEMBER_TYPES
    {
        BODY_PART = 0,
        BODY_PART_FLAG = 1,
    };

    enum BODY_PARTS
    {
        HEAD = 0,
        TORSO = 1,
        ARM = 2,
        LEG = 3,
    };

    enum BODY_PART_STATUS
    {
        FINE = 0,
        SCRATCHED = 1,
        CUT = 2,
        GASHED = 3,
        BROKEN = 4,
        MANGLED = 5,
    };
}
using namespace BODY_PARTS;

void PrintBodyPartStatus(int part[BPMEMBERS])
{
    if (part[BODY_PART] = 0 &amp;&amp; part[BODY_PART_FLAG] == 0)
    {
        cout &lt;&lt; &quot;Your head is fine&quot;;
    }

    else cout &lt;&lt; part[BODY_PART] &lt;&lt; endl &lt;&lt; part[BODY_PART_FLAG];
}



int main()
{
    int head[BPMEMBERS];

    head[BODY_PART] = HEAD;
    head[BODY_PART_FLAG] = FINE;

    PrintBodyPartStatus(head);
    return 0;
}
&lt;!--formatted--&gt;&lt;/pre&gt;

I hope that is all in code !

When I run this, I get the exception in the PrintBodyPartStatus(), which prints 0 0.
And the check above the exception, is expecting a 0, 0.
What am I missing? Am I doing this wrong? It seems like a viable way to use Enums, as I&#039;ve been using consts for EVERYTHING until I had a look at some open source game Enums.

I&#039;m currently working on this, so don&#039;t think I&#039;m commenting to expect you to do it for me (which would be nice, I admit)
But I really didnt&#039;t see the point in typing out

&lt;pre&gt;
enum COLOURS
{
    RED,
    YELLOW,
    GREEN,
    {..}
};
&lt;/pre&gt;

where in a few less line I coult just type in

&lt;pre&gt;
const int RED = 0;
const int YELLOW = 1;
const int GREEN = 2;
{..}
&lt;/pre&gt;

Thanks in advance


EDIT:
changing the check from &amp;&amp; to &#124;&#124; make it work. I&#039;ve always wondered why OR checks work properly and AND checks don&#039;t. (Maybe I&#039;ve been doing those all wrong too, but I&#039;ve always had the problem, even on simple checks.

even compound if&#039;s don&#039;t work very often
&lt;pre&gt;
if(blah)
{
      if(blah blah)
      {
             Do(blah blah blah)
      }
}
&lt;/pre&gt;
Strange.</description>
		<content:encoded><![CDATA[<pre>
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;

using namespace std;

namespace BODY_PARTS
{
    const int BPMEMBERS = 2;

    enum MEMBER_TYPES
    {
        BODY_PART = 0,
        BODY_PART_FLAG = 1,
    };

    enum BODY_PARTS
    {
        HEAD = 0,
        TORSO = 1,
        ARM = 2,
        LEG = 3,
    };

    enum BODY_PART_STATUS
    {
        FINE = 0,
        SCRATCHED = 1,
        CUT = 2,
        GASHED = 3,
        BROKEN = 4,
        MANGLED = 5,
    };
}
using namespace BODY_PARTS;

void PrintBodyPartStatus(int part[BPMEMBERS])
{
    if (part[BODY_PART] = 0 &amp;&amp; part[BODY_PART_FLAG] == 0)
    {
        cout &lt;&lt; &quot;Your head is fine&quot;;
    }

    else cout &lt;&lt; part[BODY_PART] &lt;&lt; endl &lt;&lt; part[BODY_PART_FLAG];
}

int main()
{
    int head[BPMEMBERS];

    head[BODY_PART] = HEAD;
    head[BODY_PART_FLAG] = FINE;

    PrintBodyPartStatus(head);
    return 0;
}
<!--formatted--></pre>
<p>I hope that is all in code !</p>
<p>When I run this, I get the exception in the PrintBodyPartStatus(), which prints 0 0.<br />
And the check above the exception, is expecting a 0, 0.<br />
What am I missing? Am I doing this wrong? It seems like a viable way to use Enums, as I&#8217;ve been using consts for EVERYTHING until I had a look at some open source game Enums.</p>
<p>I&#8217;m currently working on this, so don&#8217;t think I&#8217;m commenting to expect you to do it for me (which would be nice, I admit)<br />
But I really didnt&#8217;t see the point in typing out</p>
<pre>
enum COLOURS
{
    RED,
    YELLOW,
    GREEN,
    {..}
};
</pre>
<p>where in a few less line I coult just type in</p>
<pre>
const int RED = 0;
const int YELLOW = 1;
const int GREEN = 2;
{..}
</pre>
<p>Thanks in advance</p>
<p>EDIT:<br />
changing the check from &amp;&amp; to || make it work. I&#8217;ve always wondered why OR checks work properly and AND checks don&#8217;t. (Maybe I&#8217;ve been doing those all wrong too, but I&#8217;ve always had the problem, even on simple checks.</p>
<p>even compound if&#8217;s don&#8217;t work very often</p>
<pre>
if(blah)
{
      if(blah blah)
      {
             Do(blah blah blah)
      }
}
</pre>
<p>Strange.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shai</title>
		<link>http://www.learncpp.com/cpp-tutorial/45-enumerated-types/comment-page-1/#comment-69940</link>
		<dc:creator>Shai</dc:creator>
		<pubDate>Thu, 08 Oct 2009 08:35:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/45-enumerated-types/#comment-69940</guid>
		<description>Great work, Alex.
Your site is better than any C++ book I know of.</description>
		<content:encoded><![CDATA[<p>Great work, Alex.<br />
Your site is better than any C++ book I know of.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

