Intro_Class_Area
form.cpp
Go to the documentation of this file.
1 #include "form.h"
2 
3 #include <iostream>
4 using namespace std;
5 
6 // keep the CLANG compiler silent (it is right!)
7 // https://stackoverflow.com/questions/28786473/clang-no-out-of-line-virtual-method-definitions-pure-abstract-c-class
9 
10 float Quadrat::area() const
11 {
12  return _edge * _edge;
13 }
14 
15 float Circle::area() const
16 {
17  return static_cast<float>(M_PI) * _radius * _radius;
18 }
19 
20 bool operator<(const Form &a, const Form &b)
21 {
22  return a.area() < b.area();
23 }
24 
25 bool kleiner (const Form *a, const Form *b)
26 {
27  return a->area() < b->area(); // uses operator<(const Form &a, const Form &b)
28 }
29 
30 // Output-Operator : Here we benefit from polymorphism
31 ostream &operator<<(ostream &s, const Form &rhs)
32 {
33  s << rhs.classname() << " with centre ";
34  s << "(" << rhs.GetX() << "," << rhs.GetY() << ")";
35  s << " has an area of " << rhs.area();
36  return s;
37 }
float area() const override
Definition: form.cpp:15
Definition: form.h:10
virtual float area() const =0
float GetX() const
Definition: form.h:17
float GetY() const
Definition: form.h:21
virtual std::string classname() const
Definition: form.h:26
virtual ~Form()
Definition: form.cpp:8
float area() const override
Definition: form.cpp:10
bool kleiner(const Form *a, const Form *b)
Definition: form.cpp:25
bool operator<(const Form &a, const Form &b)
Definition: form.cpp:20
ostream & operator<<(ostream &s, const Form &rhs)
Definition: form.cpp:31