c++的重载是指同一函数名可实现不同的功能,成员函数被重载的特征:
(1)相同的范围(在同一个类中);
(2)函数名字相同;
(3)参数不同;
(4)virtual 关键字可有可无。

 

本次计算器中,中缀转后缀需要进行符号压栈,而计算的时候需要数字的计算,而栈的实现可以通过重载来实现,即提高效率又能更方便的使用。

示例如下:

bool Push(double i){  //不同数值代表不同符号
        lnkNode *tmp=new lnkNode(i);
        tmp->Setnext(top);
        top=tmp;
        size++;
        return true;
    }
    bool Push(long n,long d){
        lnkNode *tmp=new lnkNode(n,d);
        tmp->Setnext(top);
        top=tmp;
        size++;
        return true;
    }
    bool Pop(double &item){
        lnkNode *tmp;
        if(0==size){
            printf("emptyerror");
            return false;
        }
        item=top->Getinfo();
        tmp=top->Getnext();
        delete top;
        top=tmp;
        size--;
        return true;
    }

    bool Pop(long &n,long &d){
        lnkNode *tmp;
        if(0==size){
            printf("emptyerror");
            return false;
        }
        n = top->Getnt();
        d = top->Getdt();
        tmp = top->Getnext();
        delete top;
        top = tmp;
        size--;
        return true;
    }