Forum
Typumwandlung in C++ (Computertechnik)
Hallo Leute.
Ich habe ganz ehrlich das mit der Typumwandlung noch nicht genau verstanden.
In der "C++ Bibel" (C++ in 21 Tagen) steht dazu folgendes Beispiel:
1: #include
2:using namespace std;
3: void intDiv(int x, int y)
4: {
5: int z = x / y;
6: cout << "z: " << z << endl;
7: }
8:
9: void floatDiv(int x, int y)
10:{
11: float a = (float)x;
12: float b = static_cast
13: float c = a / b;
14:
15: cout << "c: " << c << endl;
16:}
17:
18: int main()
19: {
20: int x = 5, y = 3;
21: intDiv(x,y);
22: floatDiv(x,y);
23: return 0;
24: }
Zeilen 1 bis 7 sind klar:
Das ist eine Funktion, in der 2 Integer Typen deklariert sind. Das Einzigste, was ich mich da frage, ist die Tatsache, dass die Funktion mit "void" beginnt. "void" bedeutet doch, dass nichts zurück gegeben wird?
Zeilen 09 bis 16 sind aber unklar:
Warum schreibt man im Funktionskopf "void floatDiv(int x, int y)", wenn man im Rumpf eben 2 mal
"float b = static_cast
Gruß
Max
--
Where is the madness ...
Gesamter Thread:

