为什么静态类类型函数返回零



我正在阅读斯坦福大学教授Nick Parlante的C++Essential讲义。下面是一个代码示例:

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

我的问题是,当类型为Account时,为什么这个函数返回零?这里的意思是假的吗?

函数返回Account*,而不是Account。0是一个空指针常量。

最新更新