C++学习笔记15:操作符重载的函数原型列表(推荐)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C++学习笔记15:操作符重载的函数原型列表(推荐),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2755字,纯文字阅读大概需要4分钟。
内容图文
![C++学习笔记15:操作符重载的函数原型列表(推荐)](/upload/InfoBanner/zyjiaocheng/1331/d0abeee69674474d94a93fd0da7eca39.jpg)
// 普通四则运算 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, constint & rhs);//标量运算,如果存在 friend A operator *(constint & lhs, const A & rhs);//标量运算,如果存在 //关系操作符 friend booloperator == (const A & lhs, const A & rhs); friend booloperator != (const A & lhs, const A & rhs); friend booloperator < (const A & lhs, const A & rhs); friend booloperator <= (const A & lhs, const A & rhs); friend booloperator > (const A & lhs, const A & rhs); friend booloperator >= (const A & lhs, const A & rhs); //逻辑操作符 friend booloperator || (const A & lhs, const A & rhs); friend booloperator && (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 * operatornew(std::size_t size) throw(bad_alloc); void * operatornew(std::size_t size, const std::nothrow_t &) throw(); void * operatornew(std::size_t size, void *base) throw(); void * operatornew[](std::size_t size) throw(bad_alloc); voidoperatordelete(void *p); voidoperatordelete[](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::operatorchar *() const; A::operatorint() const; A::operatordouble() 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);
原文:http://www.cnblogs.com/hujianglang/p/6221041.html
内容总结
以上是互联网集市为您收集整理的C++学习笔记15:操作符重载的函数原型列表(推荐)全部内容,希望文章能够帮你解决C++学习笔记15:操作符重载的函数原型列表(推荐)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。