友元函式編寫運算子過載

2021-07-13 12:26:26 字數 719 閱讀 9122

/*

*檔名稱:test.cpp

*作    者:陳傳禎

*完成日期:2023年6月14日

*版 本 號:1.0

**問題描述:簡單的運算子過載

*輸入描述: 兩個複數,

*程式輸出: 兩個複數相加減的結果

*/#include 

using

namespace

std;  

class

complex  

complex(double

r,double

i)  

friend

complex operator+(complex&c1, complex &c2);  

friend

complex operator-(complex&c1 ,complex &c2);  

void

display();  

private

:  double

real;  

double

imag;  

};  

complex operator+(complex&c1,complex &c2)  

complex operator-(complex&c1, complex &c2)  

void

complex::display()  

intmain()  

運算子過載,友元函式

運算子過載 include using namespace std class cint cint const cint timp public cint operator const cint timp const cint add const cint timp const cint add c...

友元運算子過載

運算子就是一種特殊的函式 運算子過載可以是普通函式 const money operator const money a1,const money a2 可以是成員函式 const money operator const money a2 const 當二元運算子作為成員函式進行過載時,只有乙個引...

8 1 2 運算子過載(友元函式)

程式頭部注釋開始 程式的版權和版本宣告部分 檔名稱 實現複數類中的運算子過載 作 者 張傳新 完成日期 2012 年04 月07 日 版 本 號 1.0 對任務及求解方法的描述部分 輸入描述 問題描述 定義乙個複數類過載運算子 使之能用於複數的加減乘除。程式輸出 程式頭部的注釋結束 includeu...