-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
157 lines (101 loc) · 2.61 KB
/
Copy pathcomplex.cpp
File metadata and controls
157 lines (101 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
template <class T>
class Complex{
public: T real, imagine;
public:
Complex(): real(0), imagine(0){}
Complex(T _real, T _imagine): real(_real), imagine(_imagine){}
Complex(Complex &c): real(c.real), imagine(c.imagine){cout<<""<<endl;}
~Complex(){
cout<<real<<"Leave"<<endl;
// system("pause");
}
//Complex(Complex &c):real(c.real), imagine(c.imagine){}
/*
Complex print();
Complex operator + (Complex &);
*/
Complex &print(){
cout<<real<<"+"<<imagine<<"i"<<endl;
return *this;
}
Complex & operator= (const Complex & c){
// if (c==NULL) cout<<"here"<<endl;
cout<<"here"<<endl;
this->real=c.real;
imagine = c.imagine;
return *this;
}
/*
Complex & equal(const Complex &c){
// if (c==NULL) cout<<"here"<<endl;
cout<<"here"<<endl;
this->real=c.real;
imagine = c.imagine;
return *this;
}
*/
Complex & operator+=(const Complex &c){
real+=c.real;
imagine+=c.imagine;
return *this;
}
const Complex operator + (const Complex &c)const{
//Complex *c3= new Complex();
Complex c3;
c3=*this;
c3+=c;
return c3;
//return *this;
}
};
/*
Complex Complex<T>::print(){
cout<<real<<"+"<<imagine<<"i"<<endl;
return *this;
}
Complex Complex::operator + (Complex &c){
return new Complex(real+c.real, imagine+c.imagine);
}
*/
string getName(){
return "dong";
}
int main(){
Complex<double> c1(1.3,2.3), c2(2.3,3.23);
// Complex<double> c3(c1+c2);
c1+c2;
Complex<double> c3;
c3=c1+c2;
c3.print();
//c1.+(c2);
// c3.equal(c1.operator+(c2));
//c1+c2;
//Complex<double>c3((Complex<double> &)(c1+c2));
// Complex<double> c3((c1+c2).real,(c1+c2).imagine);
//string a= getName();
const
string &a = getName();
cout<<a<<endl;
// string &&b;
Complex<double> c23=c3;
// c3.print();
// c1.operator=(c2);
//c3.operator=(c1+c2);
// c1.print();
// (c1+c2).print();
// c1=c2;
system("pause");
// Complex<double> &c=(c1+c2);
// c3.operator=(c1+c2);
// c3.print();
//c3.print();
//c3.print();
// int a=5, b=21;
// a.operator+(b);
system("pause");
return 0;
}