|
|
|
|
|
|
|
|
|
|
class Square
was missing : public Shape
|
|
virtual
approach lets you deal with the shape as an abstract object. You don't care what the shape is as long as it has a perimeter() function. Granted the shape example is contrived, but it demonstrates the power of virtual
.
|
|
for
loop at line 36 shows an example where we don't care whether the player object is Human or Computer.
|
|
° The override specifier seems useless - but the function overrides the base class function. What it means? |
° Inside the base class I call directly the computation function? Is it safe? |
° Do I have to delete the dynamic memory allocation when I use a derived class? |
When I use delete s, it crashes at end... |
|
|
Do I have to delete the dynamic memory allocation when I use a derived class? |
|
|
|
|
Isocele Triangle with height 8 and base 5 has an area of 20 Rectangle with dimensions 7*5 has an area of 35 Circle with radius 9 has an area of 254.469 Destructing base class Shape and its derived struct circle Destructing base class Shape and its derived struct rectangle Destructing base class Shape and its derived struct triangle |
|
|
typeid(type).name()
is implementation defined. It's fine in debug print statements like this but you probably don't want to use it in real code, at least not if you aim to get a consistent and human readable result.Destructing base 5Shape and its derived 6circle Destructing base 5Shape and its derived 9rectangle Destructing base 5Shape and its derived 8triangle |
new Shape()
in:
|
|
main.cpp:2:16: error: expected unqualified-id constexpr auto M_PI = 3.14159265358979323846; ^ /root/emsdk/upstream/emscripten/cache/sysroot/include/math.h:375:25: note: expanded from macro 'M_PI' #define M_PI 3.14159265358979323846 /* pi */ ^ 1 error generated. |
|
|
Isocele Triangle with height 8 and base 5 has an area of 20 Destructing 8triangle Destructing base 5Shape and its derived triceratops |
|
|
|
|
|
|
Isocele Triangle with height 8 and base 5 has an area of 20 Rectangle with dimensions 7*5 has an area of 35 Circle with radius 9 has an area of 254.469 Destructing base class Shape and its derived struct circle Destructing base class Shape and its derived struct rectangle Destructing base class Shape and its derived struct triangle |
|
|
Isocele Triangle with height 8 and base 5 has an area of 20 Rectangle with dimensions 7*5 has an area of 35 Circle with radius 9 has an area of 254.469 Destructing base class Shape and its derived _circle Destructing base class Shape and its derived _rectangle Destructing base class Shape and its derived _triangle |