Hallo ich bins mal wieder..
Das mit den Standardwerten in den Funktionsparametern hab ich verstanden allerdings ist mir eine ganz andere Frage aufgekommen.
Hier mal der Code:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// C++ für Spieleprogrammierer
// Listing 11.1
// Standardwerte für Funktionsparameter
//
#include <iostream>
using namespace std;
// Prototypen
//
void ErstelleButton (const string &sText,
int Breite = 100, int Hoehe = 30);
// Hauptprogramm
//
int main ()
{
// Einige Buttons erstellen
ErstelleButton ("Kleines Icon 1");
ErstelleButton ("Kleines Icon 2");
ErstelleButton ("Mittleres Icon", 150, 45);
ErstelleButton ("Grosses Icon 1", 200, 60);
ErstelleButton ("Kleines Icon 3");
getchar ();
return (0);
}
// ErstelleButton
//
void ErstelleButton (const string &sText, int Breite, int Hoehe)
{
// Ausgabe der Buttoninformationen
cout << "Folgender Button wurde erstellt: " << endl;
cout << "Text : " << sText.c_str() << endl;
cout << "Breite: " << Breite << endl;
cout << "Hoehe : " << Hoehe << endl;
cout << endl;
} // ErstelleButton
|
Warum benutzt man zum aufrufen des Textes (der aus einer Referenz gelsen wird?!)
cout << "Text : " << sText.c_str() << endl;
und warum geht nicht einfach "sText"?
Hab auch schon zurück geblättert aber bei strings nichts in dieser Art gefunden hab wohl irgendwo etwas überlesen