zoukankan      html  css  js  c++  java
  • 运算符重载

    /*  1.只能重载c++提供的标准运算符

       2.参数个数固定

       3.针对类的对象操作

    运算符的重载形势只有两种: 一种是重载为类的友元行数

    特殊运算符的重载 “--” “++”   等等

     http://c.chinaitlab.com/special/czhenyan/Index.html

    */

    #include<iostream>
    using namespace std;
    class  base
    {
    public:
        int a1;
        float b1;
        base()
        {
            a1=0;
            b1=0.0;
            cout<<"constructing base "<<endl;
        }
        base(int a,float b)
        {
            a1=a;
            b1=b;
            cout<<"constructing base "<<endl;
           
        }
        ~base()
        {
            cout<<"desconstructing base"<<endl;
        }
        base operator +(int c);
    };
    base base::operator +(int c)
    {
        a1+=c;
        b1+=(float)c;
        cout<<"operator + success"<<endl;
        return *this;
    }
    int main(int argc,char **argv)
    {
        base o1(1,1.0),oo;
        oo=o1+5;// 隐式调用
        oo=o1.operator+(5);//显式调用
        cout<<"   "<<oo.a1<<"     "<<oo.b1<<endl;
       
    }image

  • 相关阅读:
    副本集-Replica Sets
    SpringBoot整合SpringData MongoDB
    Auth认证
    Form
    flask一些插件
    SQLAlchemy
    session
    上下文
    flask路由
    Flask中间件
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/3480086.html
Copyright © 2011-2022 走看看