Total members 11890 |It is currently Fri Apr 19, 2024 8:54 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Defining Enum in C++
cpp code
/* C enumerate type creates symbolic names.  The names have integer
values. */
#include <stdio.h>

/* This assigns the names Sun through Sat to the values 0 through 6.
They are constants, and cannot be changed. It also defines the
tag daynames which can be used to declare a variable of this type. */
enum daynames { Sun, Mon, Tue, Wed, Thu, Fri, Sat};

/* This just defines the names */
enum {SEC = 1, MIN = 60, HOUR = 60*60, DAY = 24*60*60};

int main()
{
/* Declare a variable of type enum daynames. It is really
just an integer, of some size picked by the implementation
large enough to hold all the enumeration values. */
enum daynames today;

/* This defines some names, each one taking the value one greater
if than the last, if not given a specific value. The variable
dd can hold any of the enumeratoin values. */
enum { DINK, DANK = 5, DUNK, DONGLE = 4, DANGLE, DROP } dd;
int n;

/* Days of the week. These are just integer codes. */
for(today = Mon; today <= Fri; ++today)
printf("%d ", today);
putchar('\n');

/* Using the second value constants. */
printf("Three days, four hours, and 28 minutes is %d seconds.\n",
3*DAY + 4*HOUR + 28*MIN);

/* Enum type variables are just integers. Enum values are just
integers. */
dd = 2;
printf("%d %d %d %d %d %d %d\n", DINK, DANK, DUNK, DONGLE, DANGLE,
DROP, dd);
}


The identifier after the enum keyword (dynamics for instance), is called in tag. In C++, it is also a type name, just as the name of a class. In plain C, it can be used with the enum keyword to create variables of the enumerated type.

Some languages, such as Pascal and Ada, contain a carefully designed and restricted enumerated type. The C version is much more flexible, or useless, depending on your viewpoint.



_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Enum Declaration
 JSP Declaration Tag     -  
 Typedef Declaration     -  
 Java enum example     -  
 how to use enum in jaxb unmarshalling     -  
 extending enum in java     -  
 Define enum in java     -  
 Define Enum inside a class     -  
 Passing Enum as Type Parameter to method     -  



Topic Tags

C++ Variables
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com