Type casting
type casting
cis15
advanced programming techniques, using c++
fall 2007
lecture # I.3
? used to convert between fundamental (simple) data types (e.g., int, double, char)
? there are two ways to do this
topics:
? (1) the C way (technically obsolete):
? type casting
double d = 65.0;
int i = (int)d;
char c = (char)i;
? enumeration types
? typedef
? precedence and associativity
? (2) the C++ way:
? control flow
¨C static_cast: for conversions that are ¡°well-defined, portable, invertable¡±; e.g., like
the C ways, above
¨C reinterpret_cast: for conversions that are system-dependent (not recommended)
¨C const_cast: for conversions where the value of the variable being converted cannot
be changed; data type must always be a pointer or reference
¨C dynamic_cast: for converting between classes (to be discussed later in the term)
? command line arguments
? syntax:
static_cast(variable)
cis15-fall2007-sklar-lecI.3
1
enumeration types
cis15-fall2007-sklar-lecI.3
2
? example:
void showSuit( int card ) {
enum suits { diamonds, clubs, hearts, spades } suit;
suit = static_cast( card / 13 );
switch( suit ) {
case diamonds: cout ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- botched casting 2019
- java type casting char to int
- reality tv casting calls
- c casting float to int
- casting windows 10 to chromecast
- gm differential casting number decoder
- molds for casting metal
- metal casting molds for sale
- molds for casting aluminum
- game show casting call
- game show casting 2021
- metal casting ring mold