zoukankan      html  css  js  c++  java
  • C++学习笔记15:操作符重载的函数原型列表(推荐)

    //普通四则运算
    friend A operator +(const A & lhs, const A & rhs);
    friend A operator -(const A & lhs, const A & rhs);
    friend A operator *(const A & lhs, const A & rhs);
    friend A operator /(const A & lhs, const A & rhs);
    friend A operator %(const A & lhs, const A & rhs);
    friend A operator *(const A & lhs, const int & rhs);//标量运算,如果存在
    friend A operator *(const int & lhs, const A & rhs);//标量运算,如果存在
    
    //关系操作符
    friend bool operator == (const A & lhs, const A & rhs);
    friend bool operator != (const A & lhs, const A & rhs);
    friend bool operator < (const A & lhs, const A & rhs);
    friend bool operator <= (const A & lhs, const A & rhs);
    friend bool operator > (const A & lhs, const A & rhs);
    friend bool operator >= (const A & lhs, const A & rhs);
    
    //逻辑操作符
    friend bool operator || (const A & lhs, const A & rhs);
    friend bool operator && (const A & lhs, const A & rhs);
    bool A::operator!();
    
    //正负操作符
    A A::operator +();//取正
    A A::operator -();//取负
    
    //递增递减操作符
    A & A::operator++();//前缀递增
    A  A::operator++(int);//后缀递增
    A & A::operator--();//前缀递减
    A  A::operator--(int);//后缀递减
    
    //动态存储管理操作符:全局或者成员函数均可
    void * operator new(std::size_t size) throw(bad_alloc);
    void * operator new(std::size_t size, const std::nothrow_t &) throw();
    void * operator new(std::size_t size, void *base) throw();
    void * operator new[](std::size_t size) throw(bad_alloc);
    void operator delete(void *p);
    void operator delete[](void *p);
    
    //赋值操作符
    A & operator = (A &rhs);
    A & operator = (const A & rhs);
    A & operator = (A && rhs);
    A & operator += (const A & rhs);
    A & operator -= (const A & rhs);
    A & operator *= (const A & rhs);
    A & operator %= (const A & rhs);
    A & operator &= (const A & rhs);
    A & operator /= (const A & rhs);
    A & operator |= (const A & rhs);
    A & operator ^= (const A & rhs);
    A & operator <<= (int n);
    A & operator >>= (int n);
    
    //下标操作符
    T & A::operator[] (int i);
    const T & A::operator[](int i)const;
    
    //函数调用操作符
    T A::operator()(...);//参数可选
    
    //类型转换操作符
    A::operator char *() const;
    A::operator int() const;
    A::operator double() const;
    
    //逗号操作符
    T2 operator,(T1 t1, T2 t2);//不建议重载
    
    //指针与选员操作符
    A * A::operator & ();//取址操作符
    A & A::operator *();//引领操作符
    const A & A::operator *() const;//引领操作符
    C * A::operator->();//选员操作符
    const C * A::operator->() const;//选员操作符
    C & A::operator->*(...);//选员操作符,指向类成员的指针
    
    //流操作符
    friend ostream & operator << (ostream &os, const A &a);
    friend istream & operator >> (istream &is, A &a);
    怕什么真理无穷,进一寸有一寸的欢喜。---胡适
  • 相关阅读:
    python多线程实现抓取网页
    调用百度地图实如今地图上定位
    Java创建二叉树
    J2EE的13个规范
    现场故障 案例:控制文件损坏
    数据库原理常见问答
    Lucene整理--中文分词
    Linux发行版
    python中异常好用的工具
    python有趣的一行代码
  • 原文地址:https://www.cnblogs.com/hujianglang/p/6221041.html
Copyright © 2011-2022 走看看