全局运算符重载函数例
来源:互联网 发布:潍坊网络部主管招聘 编辑:程序博客网 时间:2024/05/16 12:57
/*
我写他的目的是以防以后忘记这些基础的东西,每隔一段时间就过一遍程序,这比看书有效率
*/
#include <iostream>
using namespace std;
class point
{
private:
int x;
public:
point();
point(int);
//必须声明为友元不然不能调用私有成员x 除非公有函数int Getx();
friend int operator ! (point&);
friend int operator + (point&,int);
};
point::point():x(100){}
point::point(int a):x(a){}
int operator !(point &obj)
{
if(obj.x==0)return 0;
else
return 1;
}
int operator +(point &obj,int i)
{
int add;
add=obj.x+i;
return add;
}
int main()
{point obj_1(9);
cout<<obj_1+10<<endl;
cout<<!obj_1<<endl;
system("pause");
return 0;
}
结果为:19和1
- 全局运算符重载函数例
- C++用全局函数重载运算符
- 重载全局new运算符
- 重载全局new运算符
- 全局重载new运算符
- 部分运算符只能用友元函数(全局函数)重载 以及链式法则
- 函数 运算符 重载
- 函数 运算符 重载
- 运算符重载函数
- C++函数重载运算符重载
- 运算符重载(重载为普通函数)
- 运算符重载(重载为成员函数)
- C++重载函数与重载运算符
- 函数重载与运算符重载
- 【C++】重载运算符和重载函数
- 23-24.重载运算符,重载函数。
- C++ 重载运算符和重载函数
- 函数重载与运算符重载
- ubuntu7.10 beryl安装
- 数字电路设计中的亚稳态及其解决方法
- 网际快车(FlashGet)0day漏洞曝光
- GNU linux 下安装postgres8.1.10
- [英语阅读]58%的公众希望既有长假也有短假
- 全局运算符重载函数例
- 页面打开最大化问题
- Oracle 常用SQL查询列表
- 类成员的运算符重载函数例
- AJAX开发简略 (第二部分)
- java应用部署到mysql注意事项
- 你不在乎,我却头痛
- [英语阅读]人们更易听信流言蜚语Gossip more powerful than truth - researchers
- 学习动态性能表5-V$SESSION