ich C++ Wesentliche Handout von Stanford-Professor Nick Parlante.The liest folgenden ist ein Codebeispiel:Warum gibt die statische Klassentypfunktion null zurück?
/* If C++ kept class name information around at run-time,
this would be easier. */
static Account *RandomAccount(void) {
switch (RandomNum(3)) {
case 0: return(new Gambler); break;
case 1: return(new NickleNDime); break;
case 2: return(new MonthlyFee); break;
}
return(0);
}
static int RandomNum(int num) {
return(rand() % num);
}
Meine Frage ist, warum diese Funktion Null zurückgibt, wenn der Typ Account
ist Heißt es hier falsch?
Bitte die Implementierung der Funktion 'RandomNum' anzeigen. Bearbeiten Sie Ihren Beitrag mit der Antwort. –
Die Funktion gibt 'Account *', nicht 'Account' zurück. –
@Falmarri Ich habe keine Ahnung von schrecklichen Code, da ich nur ein Anfänger bin. Aber wenn Stanford Professor Mist-Code schreibt, dann weiß ich nicht, wem ich sonst als Anfänger hehehe. –