Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why static class type function returns zero?

Tags:

c++

function

I'm reading C++ Essential handout by Stanford professor Nick Parlante.The following is a code example:

/* 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);
}

My question is, why this function returns zero when the type is Account?Does it mean false here?


1 Answers

The function returns Account*, not Account. That 0 is a null pointer constant.

like image 133
Pete Becker Avatar answered May 09 '26 23:05

Pete Becker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!