Klasse Komplex
main.cpp
Go to the documentation of this file.
1 // Klasse Komplex
2 // ohne automatisch, implizit generierte Methoden
3 // mit Operator+
4 #include "komplex.h"
5 #include <iostream>
6 using namespace std;
7 
8 int main()
9 {
10  const Komplex a(3.2,-1.1), b(4,-1); // Konstruktor Komplex(double,double)
11  Komplex c; // Konstruktor Komplex() wird benoetigt
12 
13  c = a+b; // OK: a.operator+(const Komplex&)
14 
15 // cout << "a" << "("<< a.Get_re()<< ","<<a.Get_im() <<")" << endl;
16  cout << "Komplex::abs() " << a.abs() << " vs. abs(Komplex) " << abs(a) << endl;
17  cout << a << endl; // Ausgabeoperator
18  cout << c << endl;
19 
20  double dd(-3.2);
21  // OK: a.operator+(const Komplex&)
22  c = a + Komplex(dd,0.0);// explizites Casting double --> Komplex durch Konstruktor Komplex(double)
23  c = a + dd; // implizites Casting durch Konstruktor Komplex(double)
24  cout << c << endl;
25 
26  c = dd+a; // Achtung: keine Methode operator+(const Komplex&)
27  // fuer double verfuegbar.
28  // Daher Funktion operator+(double, const Komplex&) noetig
29  cout << c << endl;
30 
31  return 0;
32 }
double abs() const
Definition: komplex.h:89
int main()
Definition: main.cpp:8
Definition: komplex.h:9
double abs(Komplex const &rhs)
Definition: komplex.h:120