C++ Type Definitions

The format of a type definition is:

typedef <data type> <new data type>

So to define a new type Boolean:

typedef int Boolean;

Some sample C++ code using this:

const int FALSE = 0;  // now use FALSE for 0
const int TRUE  = 1;  // now use TRUE for 1

typedef int Boolean;  // new type (alias)

void main(void)
{
  Boolean a, b, c;    // declare 3 Booleans

  a = TRUE;       // set a to TRUE  (1)
  b = FALSE;      // set b to FALSE (0)
  c = a;          // set c to a     (1)

  c = 1;          // OK, Boolean is alias for int
                  //   but it's not consistent
}

Next page
Previous page
Go to Lesson 7 index.


HTML by Jennifer Keiser.
Sponsored by Inspiration, the diagramming and outlining tool.