<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Creating a Class for Enums' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Creating a Class for Enums' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 21:45:02 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 21:45:02 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Creating a Class for Enums</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/429657/429657/creating-a-class-for-enums/</link>
      <description>I'm new to learning C++ and I'm running into a bit of trouble. The book I'm learning from gives the following code, but it's not very specific when it describes the code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
1. #include &amp;lt;iostream&amp;gt;
2. #include &amp;lt;string&amp;gt;
3.
4. using namespace std;
5.
6. class Colors
7. {
8. public:
9. enum ColorEnum {blue, red, green, yellow, black};
10. Colors(Colors::ColorEnum value);
11. string AsString();
12.
13. protected:
14. ColorEnum value;
15. };
16.
17. Colors::Colors(Colors::ColorEnum initvalue)
18. {
19. value = initvalue;
20. }
21.
22. string Colors::AsString()
23. {
24. switch (value)
25. {
26. case blue:
27. return "blue";
28. case red:
29. return "red";
30. case green:
31. return "green";
32. case yellow:
33. return "yellow";
34. case black:
35. return "black";
36. default:
37. return "Not Found";
38. }
39. }
40.
41. int main()
42. {
43. Colors InkColor = Colors::red;
44. cout &amp;lt;&amp;lt; InkColor.AsString() &amp;lt;&amp;lt; endl;
45. return 0;
46. }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I understand how classes work for the most part and how switches work, but the code itself is confusing. In particular I have no idea why lines 10, 11, 17, or 22 are written the way they are.&lt;br /&gt;
&lt;br /&gt;
Line 10&lt;br /&gt;
I don't understand why the Colors::ColorEnum value is inside the parenthesis with another Colors outside.&lt;br /&gt;
&lt;br /&gt;
Line 11&lt;br /&gt;
I don't know how the value that is used by the switch later on is saved to AsString()&lt;br /&gt;
&lt;br /&gt;
Line 17&lt;br /&gt;
Once again, I'm confused by the use of parenthesis. I think this is the function described in line 10 so I guess if someone explains why line 10 is written that way this line will make sense as well.&lt;br /&gt;
&lt;br /&gt;
Line 22&lt;br /&gt;
I'm struggling to see where the value that's being tested by switch is found in AsString()&lt;br /&gt;
&lt;br /&gt;
I know this isn't the complete code, but merely the code necessary for the computer to print the actual color instead of a number when cout &amp;lt;&amp;lt; InkColor.AsString() &amp;lt;&amp;lt; endl; is called, but I really don't understand how it all goes together.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/429657/429657/creating-a-class-for-enums/</guid>
      <pubDate>Fri, 28 Sep 2012 11:07:06 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>