1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<HTML>
<HEAD>
<TITLE>ENUM keyword</TITLE>
</HEAD>
<BODY BGCOLOR="#DDDDDD">
<HR>
<CENTER>
<H1>
<FONT COLOR="#A52A2A">C++ changes to ENUM.</FONT>
</H1>
</CENTER>
<HR>
<P><FONT COLOR="#A52A2A">In the C++ world, the rules applying to
<B>enum</B> have been altered.
<ul>
<li>Definitions no longer require the enum prefix or a
<a href=../../C/SYNTAX/typedef.html>typedef</a> fudge.
</ul>
<CENTER><TABLE BORDER=0 COLS=1 WIDTH="80%" BGCOLOR="ivory" >
<TR>
<TD>
<pre>
main ()
{
enum Currancy = {STERLING, DOLLAR, RUPEE};
enum Currancy GreenBack = DOLLAR; // Valid in C and C++
Currancy Pounds = STERLING; // Valid in C++ only.
}
</pre>
</TD>
</TR>
</TABLE></CENTER>
<UL>
<LI>
<FONT COLOR="#A52A2A">An <B>enum</B> is no longer considered to be an int
datatype. Because it has its own datatype you can not perform normal arithmatic
apon <B>enum</B> variables. The following program is now invalid.</FONT></LI>
</UL>
<CENTER><TABLE BORDER=0 COLS=1 WIDTH="80%" BGCOLOR="ivory" >
<TR>
<TD>
<pre>
main ()
{
enum Currancy = {STERLING, DOLLAR, RUPEE};
Currancy Pounds = STERLING;
Pounds = 2; // Invalid Statement.
Pounds++; // Invalid Statement.
}
</pre>
</TD>
</TR>
</TABLE></CENTER>
<P>
<HR>
<H2>
<FONT COLOR="#A52A2A">Examples:</FONT></H2>
<IMG SRC="../../GRAPHICS/computer.gif" ALT="o" ><FONT COLOR="#A52A2A"> <A HREF="../EXAMPLES/enum1.cc">Example
program.</A> </FONT>
<HR>
<H2>
<FONT COLOR="#A52A2A">See Also:</FONT></H2>
<HR>
<H2>
<FONT COLOR="#000000">C References</FONT></H2>
<IMG SRC="../../GRAPHICS/whiteball.gif" ALT="o"><FONT COLOR="#000000"> <A HREF="../../C/SYNTAX/enum.html">C
version of <B>enum</B>.</A></FONT>
<P>
<hr>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">Top</a>
</td><td width="25%">
<a href="../../C/master_index.html">Master Index</a>
</td><td width="25%">
<a href="keywords.html">C++ Keywords</a>
</td><td width="25%">
<a href="../../C/FUNCTIONS/funcref.htm">Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<font color=brown>
<address>Martin Leslie
25-Oct-98</address><p>
</BODY>
</HTML>
|