Klasse Komplex
Main Page
Classes
Files
File List
File Members
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
7
Komplex::Komplex
()
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
19
Komplex::Komplex
(
const
Komplex
& org)
20
: _re(org._re), _im(org._im)
21
{
22
23
}
24
25
Komplex::~Komplex
()
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
40
Komplex
&
Komplex::operator+=
(
const
Komplex
& rhs)
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+=
54
Komplex
Komplex::operator+
(
const
Komplex
& rhs)
const
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+=
Komplex & operator+=(const Komplex &rhs)
Definition:
komplex.cpp:40
Komplex::~Komplex
virtual ~Komplex()
Definition:
komplex.cpp:25
operator<<
ostream & operator<<(ostream &s, const Komplex &rhs)
Definition:
komplex.cpp:64
std
komplex.h
Komplex::Komplex
Komplex()
Definition:
komplex.cpp:7
Komplex
Definition:
komplex.h:9
Komplex::operator+
Komplex operator+(const Komplex &rhs) const
Definition:
komplex.cpp:54
Komplex::Get_im
double Get_im() const
Definition:
komplex.h:60
Komplex::operator=
Komplex & operator=(const Komplex &rhs)
Assignment operator.
Definition:
komplex.cpp:30
Komplex::Get_re
double Get_re() const
Definition:
komplex.h:43
Generated on Fri Apr 24 2020 09:32:41 for Klasse Komplex by
1.8.11