
C++之对运算符进行重载
爱敲代码的小赤佬
自律和节制是一切幸福的开始!
展开
-
对运算符重载的函数1
#include <iostream> using namespace std; class complex { public: complex (){real=0,image=0;} complex (double r,double i){real=r,image=i;} complex operator +(complex &c2); ///声明重...原创 2019-04-10 15:03:58 · 122 阅读 · 0 评论 -
对运算符重载的函数2
//重载函数作为友元函数 #include <iostream> using namespace std; class complex { public: complex (){real=0,image=0;} complex (double r,double i){real=r,image=i;} friend complex operator +(compl...原创 2019-04-10 15:07:13 · 134 阅读 · 0 评论 -
重载双目运算符实例
/************************************************ 双目运算符是C++中最常用的运算符,有两个操作数。 *************************************************/ #include #include <string.h> using namespace std; class String { p...原创 2019-04-10 15:41:01 · 323 阅读 · 0 评论 -
转换构造函数与类型构造函数与运算符重载函数
#include <iostream> using namespace std; class complex { public: complex(){real=0;image=0;} complex(double r){real=r;image =0;} ///转换构造函数,只有一个形参。将double 转换成complex类型。 complex(doubl...原创 2019-04-11 17:10:26 · 401 阅读 · 0 评论 -
重载+转化函数
要求:实现两个日期的相减,日期和天数的加法,减法。 #include<stdio.h> #include<stdlib.h> using namespace std; class Date { public: Date(){year=0;month=0;day=0;} Date(int y,int m,int d){year=y;month=m;day=d;...原创 2019-04-25 08:57:26 · 163 阅读 · 0 评论 -
矩阵的基本运算
加,减,乘,运算 #include <stdio.h> #include <stdlib.h> #include <stdlib.h> using namespace std; class Matrix { public: Matrix(); friend Matrix operator+(Matrix &,Matrix &); ...原创 2019-04-25 09:00:26 · 224 阅读 · 0 评论 -
==,!=,+,-运算符重载
#include <stdio.h> #include <string.h> #include<stdlib.h> using namespace std; class complex { public: complex(){real=0;image=0;} complex(double r,double i){real=r;image=i;} ...原创 2019-04-25 09:04:33 · 281 阅读 · 0 评论