zoukankan      html  css  js  c++  java
  • 包含转换重载的程序

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 class Complex
     6 {
     7     public:
     8         Complex(){
     9             real=0;
    10             imag=0;
    11         }
    12         Complex(double r){
    13             real=r;
    14             imag=0;
    15         }
    16         Complex(double r,double i){
    17             real=r;
    18             imag=i;
    19         }
    20         friend Complex operator+(Complex c1,Complex c2);
    21         void display();
    22     private:
    23         double real;
    24         double imag;
    25 };
    26 
    27 Complex operator+(Complex c1,Complex c2)
    28 {
    29     return Complex(c1.real+c2.real,c1.imag+c2.imag);
    30 }
    31 
    32 void Complex::display()
    33 {
    34     cout<<"("<<real<<","<<imag<<"i)"<<endl;
    35 }
    36 
    37 int main(int argc, char** argv) {
    38     Complex c1(3,4),c2(5,-10),c3;
    39     c3=c1+2.5;
    40     c3.display();
    41     return 0;
    42 }
  • 相关阅读:
    码云的安装和配置
    Python解释器安装教程和环境变量配置
    Python基础学习
    buuctf CheckIn
    各种小马收集
    buuctf Easysql 小记
    locust
    封装好的日志模块
    实用的测试网站
    列表操作
  • 原文地址:https://www.cnblogs.com/borter/p/9405437.html
Copyright © 2011-2022 走看看