O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Declaring Enumerated Types

An enumerated type is a data type whose variables can only take on a value from the set of constants listed in the type declaration (enumerated means “named one by one”). For instance, you can declare an enumerated type anOperator, and you can offer six possible values for it: add, subtract, multiply, divide, reset, and query (these are just like the Accumulator() operators).

The syntax for enumerated types is

enum{constantname,constantname...} ;

Here's an example:

enum anOperator {add,subtract,multiply,divide,reset,query} ;

This statement has two purposes:

  1. It makes anOperator the name of a new type, and restricts it to having one of the six specified values, just as an int is restricted to having numbers without ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required