<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Enum C# vs C++</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Enum C# vs C++</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Tue, 21 May 2013 16:38:14 GMT</pubDate>
	<lastBuildDate>Tue, 21 May 2013 16:38:14 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>9</c9:totalResults>
	<c9:pageCount>-9</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p>In C# this is perfectly legal :<br /><br />enum A<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;None,<br />&nbsp;&nbsp;&nbsp;&nbsp;Value1,<br />&nbsp;&nbsp;&nbsp;&nbsp;Value2<br />}<br /><br />enum B<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;None,<br />&nbsp;&nbsp;&nbsp;&nbsp;Sometype1,<br />&nbsp;&nbsp;&nbsp;&nbsp;Sometype2<br />}<br /><br />C&#43;&#43; complain that None is already define, so is it possible to accomplish the same thing in C&#43;&#43; ?
<br /><br />Thanks</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/446478#446478</link>
		<pubDate>Tue, 02 Dec 2008 19:54:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/446478#446478</guid>
		<dc:creator>cro</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/cro/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p>No.&nbsp; According to the C standard, identifiers in an enumerator list must be distinct from all other identifiers declared in the same scope.<br /><br />EDIT:&nbsp; After reading the C&#43;&#43; standard, it should seem that I'm wrong <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-4.gif' alt='Tongue Out' />&nbsp; If you declare your enum as enum class, you should be able to reuse names.&nbsp; So it would look like this:<br /><br /><pre class="brush: text">enum class A
{
    None,
    Value1,
    Value2
}

enum class B
{
    None,
    Sometype1,
    Sometype2
}

//... where you're using these enums

B someVariable = B::None;
B someOtherVariable = B::Value1;
A yetAnotherVariable = A::None;
</pre><br /><br />Downsides:&nbsp; you have to use A:: or B:: to access the enum's values and you can't treat your enumeration's values as an int or bool anymore (so int number = A::None and A enumValue = 1 will not work).<br /><br />EDIT2:&nbsp; enum class doesn't seem to be in the C&#43;&#43; 1998 standard...&nbsp; your mileage may vary (it may or may not be implemented in Visual Studio; can't try right now).&nbsp; Guess I should be more careful which document I pull up (I grabbed the Oct. 2008 draft of the
 C&#43;&#43; standard).&nbsp; If it's not in VS, your best bet is to prefix your constants with some distinct prefix (like ANone and BNone).<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/f5a98d703427423c84ba9deb00020cb8#f5a98d703427423c84ba9deb00020cb8</link>
		<pubDate>Tue, 02 Dec 2008 22:07:54 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/f5a98d703427423c84ba9deb00020cb8#f5a98d703427423c84ba9deb00020cb8</guid>
		<dc:creator>JonathonW</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/CannotResolveSymbol/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">CannotResolveSymbol said:</div><div class="quoteText">No.&nbsp; According to the C standard, identifiers in an enumerator list must be distinct from all other identifiers declared in the same scope.<br /><br />EDIT:&nbsp; After reading the C&#43;&#43; standard, it should seem that I'm wrong <img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-4.gif" alt="Tongue Out">&nbsp; If you declare your enum as enum class, you should be able to reuse names.&nbsp; So it would
 look like this:<br /><br /><pre class="brush: text">enum class A
{
    None,
    Value1,
    Value2
}

enum class B
{
    None,
    Sometype1,
    Sometype2
}

//... where you're using these enums

B someVariable = B::None;
B someOtherVariable = B::Value1;
A yetAnotherVariable = A::None;
</pre>
<br /><br />Downsides:&nbsp; you have to use A:: or B:: to access the enum's values and you can't treat your enumeration's values as an int or bool anymore (so int number = A::None and A enumValue = 1 will not work).<br /><br />EDIT2:&nbsp; enum class doesn't seem to be in the C&#43;&#43; 1998 standard...&nbsp; your mileage may vary (it may or may not be implemented in Visual Studio; can't try right now).&nbsp; Guess I should be more careful which document I pull up (I grabbed the Oct. 2008 draft of the
 C&#43;&#43; standard).&nbsp; If it's not in VS, your best bet is to prefix your constants with some distinct prefix (like ANone and BNone).<br /></div></blockquote>enum class is a construct of C&#43;&#43;/CLI, it defines a managed enum type. It is not available in regular C&#43;&#43;.<br /><br />I don't believe there is a way to do what you want&nbsp;using standard&nbsp;C&#43;&#43;. At least not in C&#43;&#43;98 or C99.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/893c0a67e9204a26aa859deb00020ce3#893c0a67e9204a26aa859deb00020ce3</link>
		<pubDate>Wed, 03 Dec 2008 03:50:21 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/893c0a67e9204a26aa859deb00020ce3#893c0a67e9204a26aa859deb00020ce3</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">CannotResolveSymbol said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
enum class is a construct of C&#43;&#43;/CLI, it defines a managed enum type. It is not available in regular C&#43;&#43;.<br /><br />I don't believe there is a way to do what you want&nbsp;using standard&nbsp;C&#43;&#43;. At least not in C&#43;&#43;98 or C99.</div></blockquote>enum class is planned for C&#43;&#43; 0x; when I pulled up the C&#43;&#43; standard, I grabbed the latest draft instead of the current version...&nbsp; my mistake.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/b717aae02a73422c92069deb00020d0b#b717aae02a73422c92069deb00020d0b</link>
		<pubDate>Wed, 03 Dec 2008 04:27:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/b717aae02a73422c92069deb00020d0b#b717aae02a73422c92069deb00020d0b</guid>
		<dc:creator>JonathonW</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/CannotResolveSymbol/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">CannotResolveSymbol said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Sven Groot said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
enum class is planned for C&#43;&#43; 0x; when I pulled up the C&#43;&#43; standard, I grabbed the latest draft instead of the current version...&nbsp; my mistake.<br /></div></blockquote>I see, I haven't been keeping up with the developments in C&#43;&#43;0x. It's good to know though. Right now there's no way though.<br /><br />VC9 already supports it, but as part as C&#43;&#43;/CLI so it only works when compiling with /clr, unfortunately. Hopefully VC10 will support it in regular C&#43;&#43; too, which it might since they announced it'd have some C&#43;&#43;0x features iirc.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/3d479ea36e9b436b9e669deb00020d33#3d479ea36e9b436b9e669deb00020d33</link>
		<pubDate>Wed, 03 Dec 2008 06:49:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/3d479ea36e9b436b9e669deb00020d33#3d479ea36e9b436b9e669deb00020d33</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p>Maybe I can go with something like this until C&#43;&#43; 0x is release and implemented in gcc and VC compiler ?
<br /><br /><p>class A<br />{<br />public:<br />&nbsp;&nbsp;&nbsp;&nbsp;enum Value { None, Value1, Value2 };<br />};</p>
<p>class B<br />{<br />public:<br />&nbsp;&nbsp;&nbsp;&nbsp;enum Value { None, SomeType1, SomeType2 };<br />};</p>
<p>int main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;A::Value a = A::None;<br />&nbsp;&nbsp;&nbsp;&nbsp;B::Value b = B::None;<br />}</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/11403a95a2ff4257af439deb00020d5b#11403a95a2ff4257af439deb00020d5b</link>
		<pubDate>Thu, 04 Dec 2008 13:24:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/11403a95a2ff4257af439deb00020d5b#11403a95a2ff4257af439deb00020d5b</guid>
		<dc:creator>cro</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/cro/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">cro said:</div><div class="quoteText">Maybe I can go with something like this until C&#43;&#43; 0x is release and implemented in gcc and VC compiler ?
<br /><br /><p>class A<br />{<br />public:<br />&nbsp;&nbsp;&nbsp;&nbsp;enum Value { None, Value1, Value2 };<br />};</p>
<p>class B<br />{<br />public:<br />&nbsp;&nbsp;&nbsp;&nbsp;enum Value { None, SomeType1, SomeType2 };<br />};</p>
<p>int main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;A::Value a = A::None;<br />&nbsp;&nbsp;&nbsp;&nbsp;B::Value b = B::None;<br />}</p>
</div></blockquote>
<p>That'd work. With some trickery you would be able to declare&nbsp;variables&nbsp;without using the ::Value bit too, like this:<br /><br /><pre class="brush: cpp">class MyEnum
{
public:
    enum Value
    {
        None,
        Value1,
        Value2
    };

    MyEnum(Value value) : _value(value) { }

    operator Value() const
    {
        return _value;
    }
private:
    Value _value;
};</pre><br /><br />Then you could simply use it as:<br /><pre class="brush: cpp">MyEnum x = MyEnum::Value1;</pre><br /><br />You'd have to repeat that code for every enum though.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/7f8307e173dc4097ae989deb00020d85#7f8307e173dc4097ae989deb00020d85</link>
		<pubDate>Thu, 04 Dec 2008 15:27:27 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/7f8307e173dc4097ae989deb00020d85#7f8307e173dc4097ae989deb00020d85</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">cro said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>That'd work. With some trickery you would be able to declare&nbsp;variables&nbsp;without using the ::Value bit too, like this:<br /><br /></p>
<pre class="brush: cpp">class MyEnum
{
public:
    enum Value
    {
        None,
        Value1,
        Value2
    };

    MyEnum(Value value) : _value(value) { }

    operator Value() const
    {
        return _value;
    }
private:
    Value _value;
};</pre>
<br /><br />Then you could simply use it as:<br /><pre class="brush: cpp">MyEnum x = MyEnum::Value1;</pre>
<br /><br />You'd have to repeat that code for every enum though.
<p></p>
</div></blockquote>
<p>Thanks !</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/7ce6dc5fa8fa42079e179deb00020dad#7ce6dc5fa8fa42079e179deb00020dad</link>
		<pubDate>Thu, 04 Dec 2008 20:16:25 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/7ce6dc5fa8fa42079e179deb00020dad#7ce6dc5fa8fa42079e179deb00020dad</guid>
		<dc:creator>cro</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/cro/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enum C# vs C++</title>
		<description><![CDATA[<p>OR, you could try using namespaces:<br /><br /><pre>
namespace A {
	enum AA{ None, Value1, Value2 };
}

namespace B {
	enum BB { None, Sometype1, Sometype2 };
}

...
...
	int a   = A::None;
	int aa  = A::AA::None;
	int b   = B::None;
	int bb  = B::BB::None;
</pre>
EDIT: added some namespace/name permutations. PS: I don't think I like this new editor...</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/6d076c7dbf0749d2a3589deb00020ded#6d076c7dbf0749d2a3589deb00020ded</link>
		<pubDate>Fri, 05 Dec 2008 23:23:35 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/446478-Enum-C-vs-C/6d076c7dbf0749d2a3589deb00020ded#6d076c7dbf0749d2a3589deb00020ded</guid>
		<dc:creator>RichardRudek</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/RichardRudek/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>