01 // static_cast
02 // Datei: stacast1.cpp
03
04 #include <iostream.h>
05 class bk              // Basisklasse
06 { int x;
07 };
08 class ak : private bk  // abgeleitete Klasse
09 {
10 int a1;
11 };
12
13 bk b1;               // Objektdefinitionen
14 ak a1;
15
16 int main ()
17 {
18 enum ampel { rot, gelb, gruen };
19 int y = 99;
20 ampel e0 = gelb;;
21 void * vp;
22
23 char c1 =  static_cast<char>(y);   // Standard
24 int xx =   static_cast<int>(e0);   // Standard
25 bk *bp =   static_cast<bk *>(&a1); // Standard
26 ak *ap =   static_cast<ak *>(&b1);//Bedenklich
27 ampel e1 = static_cast<ampel>(4);  //Bedenklich
28 float *fp= static_cast<float *>(NULL);//Standard
29 int * ip = static_cast<int *>(vp); // void*/int*
30 cout << e1 << endl;
31 return 0;
32 }
33

Bild 16-9  Compiler-Typwandlungen (static_cast)