Forum

Einloggen | Registrieren | RSS  

Typumwandlung in C++ (Computertechnik)

verfasst von silent_max(R) E-Mail, 26.11.2011, 15:04 Uhr

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(y);
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(y)" schreibt??

Gruß

Max

--
Where is the madness ...



Gesamter Thread:

Typumwandlung in C++ - silent_max(R), 26.11.2011, 15:04 (Computertechnik)
Ich seh den Fehler nicht *heul* - silent_max(R), 26.11.2011, 16:30
Typumwandlung in C++ - hws(R), 26.11.2011, 18:19
Typumwandlung in C++ - silent_max(R), 26.11.2011, 19:18