- Remember a data type is a set of values, along with operations on those values.
- From chapter 3:
-
- As you will note, we have one more simple type: enum
- Two address types:pointer and reference
- And the structured types
- both string and stream are class types.
- The simple types are known as atomic types
- This is because we can't break them up any further.
- As opposed to the string, which we can break into characters
- If you have not yet seen the sizeof function:
- std::size_t sizeof(type)
- std::size_t sizeof(expression)
- This returns the size, in bytes
- typedef allows you to rename a data type.S
- typedef existing_data_type identifier;
- Here we don't really create a new data type, we just rename an existing one
- This is done in the declaration area (constants, function prototypes, ...)
- Probably before any of those pieces.
- I like to follow the function naming conventions, but end with a T
- typedef float NewNumberT;
- After declared, they can be used as a normal type.
- MyNumberT functionOne(MyNumberT x, MyNumberT y);
- const MyNumberT A_VALUE = 3.423;
- MyNumberT base;
- Enumerated types
- look at problem 1 page 493.
- How will we store the planet?
- A string?
- An integer (as in Hangman?)
- Both of these seem less than satisfying.
- C++ provides another way to accomplish this
- An enumerated type is a user-defined data type whose domain is an ordered set of literal values expressed as identifiers.
- enum identifier {enumerator_list}
- an enumerator is one of the values in the list.
- An enumerator is an identifier, followed by an optional assignment to an integer or another enumerator.
- By default the first value is 0
- And each value after that is the previous + 1.
- Enumerated types
- There is no default I/O on enumerated types. (They act as integers)
- Comparison works.
- Math does not work (++, +=, ...)
- They can be passed as parameters and returned as values of functions.