总结运算符重载的方法
来源:互联网 发布:bytebuffer.js 下载 编辑:程序博客网 时间:2024/06/01 07:47
总结运算符重载的用法
以重载运算符’+’为例:
1.声明运算符重载函数:
class complex
{
public:
complex operator+(complex &c1);
private:
double real;
double imag;
};
//重载运算符函数的实现
complex complex::operator+(complex &c1)
{
return(real+c1.real,imag+c2.imag);
}
2.声明运算符重载函数:
class complex
{
public:
complex operator+(complex &c1,complex &c2);
private:
double real;
double imag;
};
//重载运算符函数的实现
complex complex::operator+(complex &c1,complex &c2)
{
return (c1.real+c2.real,c1.imag+c2.imag);
}
3.声明运算符重载函数:
class complex
{
public:
complex operator+(complex &c1);
private:
double real;
double imag;
};
//重载运算符函数的实现
complex complex::operator+(complex &c1)
{
double r,t;
r = real+c1.real;
t = imag+c1.imag;
return(complex(t,r));
}
4.声明运算符重载函数:
class complex
{
public:
complex operator+(complex c1);
private:
double real;
double imag;
};
//重载运算符函数的实现
complex complex::operator+(complex c1)
{
complex t;
t.real = c1.real+real;
c.imag = c1.imag+imag;
return complex(t.real,t.imag);
}
- 总结运算符重载的方法
- 运算符的重载方法
- 运算符重载的方法
- 运算符重载总结
- 算术运算符重载后的总结
- C++运算符重载的方法
- C++运算符重载的方法
- C++运算符重载的方法
- C++中运算符重载的方法
- c++运算符重载的方法提要
- 运算符重载 重载的两种方法 +
- (总结)C++运算符重载
- 关于运算符重载(总结)
- 关于运算符重载(总结)
- c++运算符重载总结
- c++运算符重载总结
- C++运算符重载总结
- C++运算符重载总结
- HDU3306(科波菲尔数列+快速幂)
- 上篇日本人经营之道 一制造轰动效应出奇制胜
- Redis总结
- Mysql帐号远程登陆时 ERROR 1130 的解决办法
- 破解软件的思路
- 总结运算符重载的方法
- git使用说明
- JVM调优总结
- java保留两位小数4种方法
- C/C++二维指针的使用
- 关于netbeans字体设置问题的终极解决方法
- C#如何解析wsdl文件列出方法名和参数
- 一 插入排序(insertsort和shellsort)
- 分享对Java Map集合的简单小结