Klasse Komplex
komplex.cpp
Go to the documentation of this file.
1 #include "komplex.h"
2 #include <iostream>
3 using namespace std;
4 
5 // Methoden der Klasse Komplex
6 
8  : _re(0.0), _im(0.0)
9 {
10  //ctor
11 }
12 
13 Komplex::Komplex(double re, double im)
14  : _re(re), _im(im)
15 {
16  //ctor
17 }
18 
20  : _re(org._re), _im(org._im)
21 {
22 
23 }
24 
26 {
27  //dtor
28 }
29 
30 Komplex& Komplex::operator=(const Komplex& rhs) // Assignment operator
31 {
32  if ( this!=&rhs) // Avoids self-assignment (critical with dynamic memory)
33  {
34  _re = rhs._re;
35  _im = rhs._im;
36  }
37  return *this;
38 }
39 
41 {
42  _re += rhs._re;
43  _im += rhs._im;
44  return *this;
45 }
46 
47 
48 //Komplex Komplex::operator+(const Komplex& rhs) const
49 //{
50  //Komplex tmp(_re+rhs._re, _im+rhs._im);
51  //return tmp;
52 //}
53 // geschicktere Implementierung unter Nutzung von operator+=
55 {
56  Komplex tmp(*this);
57  return tmp+=rhs;
58 }
59 
60 // Ende: Methoden der Klasse Komplex
61 // -------------------------------------------------------------------------
62 // Funktionen, welche die Klasse Komplex als Datentyp benutzen
63 
64 ostream& operator<<(ostream& s, const Komplex& rhs)
65 {
66  s << "("<< rhs.Get_re()<< ","<<rhs.Get_im() <<")";
67  return s;
68 }
69 
70 Komplex operator+(double lhs, const Komplex& rhs)
71 {
72 // Komplex tmp(lhs+rhs.Get_re(), rhs.Get_im());
73 // return tmp;
74  return rhs+lhs; // Ruft Methode operator+ der Klasse Komplex: rhs.operator(lhs)
75 
76 }
Komplex & operator+=(const Komplex &rhs)
Definition: komplex.cpp:40
virtual ~Komplex()
Definition: komplex.cpp:25
ostream & operator<<(ostream &s, const Komplex &rhs)
Definition: komplex.cpp:64
Komplex()
Definition: komplex.cpp:7
Definition: komplex.h:9
Komplex operator+(const Komplex &rhs) const
Definition: komplex.cpp:54
double Get_im() const
Definition: komplex.h:60
Komplex & operator=(const Komplex &rhs)
Assignment operator.
Definition: komplex.cpp:30
double Get_re() const
Definition: komplex.h:43