complex_test.cpp尽可能注释

来源:互联网 发布:vision软件怎么画图 编辑:程序博客网 时间:2024/06/07 03:32
#include <iostream>         //包含iossream头文件#include "complex.h"//包含 complex.h头文件using namespace std;//使用标准命名空间ostream&//重定义<<操作符,返回值类型为ostream 引用operator << (ostream& os, const complex& x)//传入参数(ostream 引用,complex常量引用){  return os << '(' << real (x) << ',' << imag (x) << ')';//返回是一个。。。的内容,通过引用传递}int main(){  complex c1(2, 1);  complex c2(4, 0);  cout << c1 << endl;  cout << c2 << endl;    cout << c1+c2 << endl;  cout << c1-c2 << endl;  cout << c1*c2 << endl;  cout << c1 / 2 << endl;    cout << conj(c1) << endl;  cout << norm(c1) << endl;  cout << polar(10,4) << endl;    cout << (c1 += c2) << endl;  /*  执行+=操作时,将c2的引用传入,执行  complex::operator += (const complex& r) {  return __doapl (this, r); } this是c1的自身指针,与r一起执行 inline complex&//设成内联函数 __doapl (complex* ths, const complex& r) { ths->re += r.re;//指针用->,对象用 . ths->im += r.im;//在类声明中,已经将其设置成友元函数,可直接使用私有数据 return *ths;//指针所代表的数据,这个数据用引用方式被其他使用 } 返回指针所代表的数据引用 返回引用  */    cout << (c1 == c2) << endl;  cout << (c1 != c2) << endl;  cout << +c2 << endl;  cout << -c2 << endl;    cout << (c2 - 2) << endl;  cout << (5 + c2) << endl;    return 0;}

0 0