Fahrzeuge 2
main.cpp
Go to the documentation of this file.
1
// C++ Vorlesung 2. Juni 2012
2
// Klassenhierarche mit virtuellen Methoden
3
4
// v_10a --> v_10b
5
// T h e O n l y c h a n g e s: Marking methods classname() and verbrauch() in Fahrzeug as virtual
6
7
/*
8
g++ -pedantic -std=c++11 -Weffc++ -Wall -Wextra -pedantic -Wswitch-default -Wfloat-equal -Wundef -Wredundant-decls -Winit-self -Wshadow -Wparentheses -Wshadow -Wunreachable-code -Wuninitialized -Wmaybe-uninitialized *.cpp
9
cppcheck --enable=all --inconclusive --std=c++11 --std=posix --suppress=missingIncludeSystem *.cpp
10
clang++ -std=c++11 -fsyntax-only -Wdocumentation -Wconversion -Wshadow -Wfloat-conversion -pedantic *.cpp
11
clang++ -std=c++11 -Weverything *.cpp
12
clang++ -cc1 --help
13
*/
14
15
#include "
fahrzeug.h
"
16
#include <iostream>
17
#include <typeinfo>
// operator typeid
18
using namespace
std;
19
24
void
PrintInfo
(
const
Fahrzeug
& p);
25
26
27
28
int
main
()
29
{
30
cout <<
"Hello world!"
<< endl;
31
32
Fahrzeug
a(1768);
33
cout << a.
classname
() << endl;
34
//cout <<typeid(a).name() << endl;
35
36
LKW
b(2500, 3100);
37
cout << b.
classname
() <<
" "
<< b.
Get_load
() << endl;
38
//cout <<typeid(b).name() << endl;
39
40
PKW
c(1459, 3);
41
cout << c.
classname
() <<
" "
<< c.
Get_pass
() << endl;
42
43
MAN
l1(7500, 10100);
44
Raba
l2 (3500, 4000);
45
46
Opel
p1(1450);
47
Smart
p2 (1100);
48
49
//
50
PrintInfo
(a);
// basis class ==> correct information is printed
51
PrintInfo
(p1);
// derived class ==> correct information is printed, because of virtual methods!!
52
53
return
0;
54
}
55
56
57
void
PrintInfo
(
const
Fahrzeug
& p)
58
{
59
cout << p.
classname
() <<
" : "
<< p.
Get_kg
() <<
" kg and "
60
<< p.
verbrauch
() <<
" l/100km"
<< endl;
61
}
Fahrzeug
Definition:
fahrzeug.h:5
Fahrzeug::classname
virtual std::string classname() const
Definition:
fahrzeug.h:18
Fahrzeug::Get_kg
int Get_kg() const
Definition:
fahrzeug.h:16
Fahrzeug::verbrauch
virtual float verbrauch() const
Definition:
fahrzeug.h:23
LKW
Definition:
fahrzeug.h:32
LKW::Get_load
int Get_load() const
Definition:
fahrzeug.h:41
LKW::classname
std::string classname() const override
Definition:
fahrzeug.h:42
MAN
Definition:
fahrzeug.h:68
Opel
Definition:
fahrzeug.h:93
PKW
Definition:
fahrzeug.h:49
PKW::classname
std::string classname() const override
Definition:
fahrzeug.h:59
PKW::Get_pass
int Get_pass() const
Definition:
fahrzeug.h:58
Raba
Definition:
fahrzeug.h:80
Smart
Definition:
fahrzeug.h:107
fahrzeug.h
PrintInfo
void PrintInfo(const Fahrzeug &p)
Prints some info from a vehicle.
Definition:
main.cpp:57
main
int main()
Definition:
main.cpp:28
main.cpp
Generated by
1.9.1