简小的C++基础--重载运算符1
来源:互联网 发布:信访网络舆情工作方案 编辑:程序博客网 时间:2024/06/10 23:42
#include <iostream>using namespace std;class Complex{public: Complex(){real = 0;imag = 0;} Complex(double r,double i){real = r;imag = i;} friend Complex operator+(Complex &c1,Complex &c2); void display();private: double real; double imag;};Complex operator+(Complex &c1,Complex &c2){ return Complex(c1.real + c2.real,c1.imag + c2.imag);}void Complex::display(){ cout << "(" << real <<"," << imag << "i)" <<endl;}int main(int argc, char *argv[]){ cout << "Hello World!" << endl; Complex c1(4,5),c2(1,-12),c3; c3 = c1 + c2; cout << "c1 = " ; c1.display(); cout << "c2 = " ; c2.display(); cout << "c3 = " ; c3.display(); return 0;}
阅读全文
0 0
- 简小的C++基础--重载运算符1
- 简小的C++基础--重载运算符2
- <C/C++基础> 重载运算符
- 【C++】C++运算符重载-基础
- c++-运算符的重载
- C++--运算符的重载
- 运算符重载的小项目展示
- [C/C++]运算符的重载
- 基础:运算符重载
- 运算符重载小程序1
- c#基础 运算符的重载
- C++-运算符重载
- [C++]重载运算符
- C#:运算符重载
- c++-++运算符重载
- C++:重载运算符
- 运算符重载(C++)
- [c++]运算符重载
- python3.5-igraph实例操作(一)
- H264编解码框架简介
- Codeforces 767C Garland (dfs)
- 关于git bush 中不能复制黏贴的问题
- c++ 比较操作符利用rel_ops生成引用
- 简小的C++基础--重载运算符1
- storm-[7]-Trident State学习
- c++作业6
- mysql(九)MySQL如何执行关联查询
- leetcode-46. Permutations(非重复元素全排列)
- 引用和指针的区别
- 洛谷 P1018 乘积最大
- #include <>与#include“ ”
- 排序算法总结(3)--冒泡排序