-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplex_v2.cc
55 lines (44 loc) · 1002 Bytes
/
Complex_v2.cc
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
#include <iostream>
class Complex
{
public:
Complex() {
std::cout << "Complex::Complex()" << std::endl;
re = 0.0;
im = 0.0;
}
Complex(double x) {
std::cout << "Complex::Complex(double)" << std::endl;
re = x;
im = 0.0;
}
Complex(double r, double i) {
std::cout << "Complex::Complex(double, double)" << std::endl;
re = r;
im = i;
}
Complex operator + (const Complex &z ) const {
std::cout << "Complex::operator + (const Complex &z) const"
<< std::endl;
return Complex(re + z.re, im + z.im);
}
Complex operator * (const Complex &z) const {
std::cout << "Complex::operator * (const Complex &z) const"
<< std::endl;
return Complex(re*z.re - im*z.im);
}
private:
double re, im;
};
// int main(int argc, char **argv) {
// Complex z = 3.0;
// Complex y;
// y = 5.0;
// return 0;
// }
int main(int argc, char **argv) {
Complex z = 3.0;
Complex y;
y = z + 5.0;
return 0;
}