C++: A Wild Ride (2024-09-30 - 2024-10-04)¶
“New” vs. “Old” C++: An Overview¶
C++ is a huge pile of language constructs built on top of each other, always backwards compatible with its origins. In 2011, C++ got a major overhaul which is still ongoing. It is not always easy for someone who is new to C++ to understand why things are how they are.
A Live-Hacked Tour Around The New C++ tries to draw the boundary between the old and new C++.
“New” C++: Syntactic Goodies (Pythonicity)¶
From New Language Features:
Back To The Beginnings Of C++: What Everybody Has To Know¶
From C To C++¶
From Data Encapsulation
Classes And Methods (And Functions)¶
Templates¶
From C++ Template Basics
Exercises¶
Sensor classes, independent types
A (template) function to calculate the average of a number of sensor instances
Sensor “configuration”: a
std::map
(see “New” vs. “Old” C++: An Overview how this is done) of shapesensor-name -> sensor*
, encapsulated in a class
Inheritance, And Interfaces¶
Exercises¶
Refactoring
Sensor classes, being-an interface type
Funtion
average()
accepts different kinds of sensorsSensor config, ditto
Data logger, initial version.
Everybody has understood how
average()
works (using the sensor interface). Write a program that take a sensor configuration, and repeatedly writes measured values tostd::cout
.
Overengineering (Err, OO Design)¶
Exercises¶
What’s bad about logging to std::cout
? (Answer: not easily
replaced with different logging targets.)
Dependency Injection and Dependency Inversion (and the Strategy Pattern) are different words for one things: software structure.
Idea …
Define another interface: logging target (and make
std::cout
logging its first concrete implementation)Discuss MQTT, or SQLite3, …
Define a data logger main loop class
More Design Patterns¶
From Design Patterns With C++:
More C++ >= 11¶
OO Features¶
Memory Management¶
Exercise¶
Convert all interface usage to std::shared_ptr<>
(Sensor*
,
LoggingTarget*
)
Move Semantics, And Perfect Forwarding¶
From Move Semantics, Rvalue References:
Same syntax, different meaning …
Exercise¶
Convert all interface usage to std::unique_ptr<>
(Sensor*
,
LoggingTarget*
)
Functional: An Alternative To Full Polymorphism¶
Going Embedded¶
Optional Topics¶
Excerpts from CMake: Introduction and CMake: Advanced Topics
From Performance
Warum sollen c-casts vermieden werden?
Projektaufbau
Verwendung von statischen Libraries? -> CMake
Projekt review