From 745ab41c9d9f09d5f28f74449eb966c067cc199b Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 13 Nov 2018 08:48:24 +0100 Subject: [PATCH] =?UTF-8?q?05=5FOOb:=20Vorbereitungen=20f=C3=BCr=20Testat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Theiner --- src/05_OO/b/MP/main_mp4_OO_b.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/05_OO/b/MP/main_mp4_OO_b.cpp b/src/05_OO/b/MP/main_mp4_OO_b.cpp index 907263c..cf8412a 100644 --- a/src/05_OO/b/MP/main_mp4_OO_b.cpp +++ b/src/05_OO/b/MP/main_mp4_OO_b.cpp @@ -152,27 +152,27 @@ bool HeapObject::assertionsHold(){ return true; } - class K : public HeapObject { public: - K(){std::cout << "+K ";} + K(){std::cout << "+K ";} ~K(){std::cout << "-K ";} }; -class L { +class M : public K{ +public: + //B b; für Modifikation 5 einkommentieren + M(){std::cout << "+M ";} + ~M(){std::cout << "-M ";} +}; + +class L : public M{ public: L(){std::cout << "+L ";} ~L(){std::cout << "-L ";} }; -class M { -public: - M(){std::cout << "+M ";} - ~M(){std::cout << "-M ";} -}; - void pattern1() { B b; { @@ -187,6 +187,11 @@ void pattern2() { A a; } +B AtoB(A &a) { + B &b = reinterpret_cast(a); + return b; +} + void pattern3() { A a1; { @@ -194,6 +199,8 @@ void pattern3() { { B b; } + } + { C c; } } @@ -222,6 +229,9 @@ int main(int argc, const char * argv[]) { pattern2(); std::cout << std::endl; pattern3(); + std::cout << std::endl; + L *p = new L(); + delete p; return 0; }