From 229973910d4d21ff64bc04054d18163b42d3efcf Mon Sep 17 00:00:00 2001 From: b0rbor4d Date: Wed, 15 Apr 2026 00:18:28 +0200 Subject: [PATCH] Add C++ example: README.md --- src/cpp_examples/README.md | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/cpp_examples/README.md diff --git a/src/cpp_examples/README.md b/src/cpp_examples/README.md new file mode 100644 index 0000000..5807159 --- /dev/null +++ b/src/cpp_examples/README.md @@ -0,0 +1,72 @@ +# C++ Beispiele + +Dieses Verzeichnis enthält C++-Vergleichsbeispiele zu den C-Modulen. + +## Übersicht + +| Datei | C-Modul | Konzept | +|-------|---------|---------| +| `module1_memory_cpp.cpp` | Modul 1 | new/delete, Smart Pointers, RAII | +| `module5_datastructures_cpp.cpp` | Modul 5 | STL (vector, list, map, algorithms) | +| `module7_oop_cpp.cpp` | Modul 7 | Klassen, Vererbung, Polymorphie | +| `module8_stl_cpp.cpp` | Modul 8 | Iteratoren, Funktoren, Lambdas | + +## Kompilieren + +```bash +# Alle Beispiele +g++ -std=c++17 -o memory module1_memory_cpp.cpp +g++ -std=c++17 -o datastruct module5_datastructures_cpp.cpp +g++ -std=c++17 -o oop module7_oop_cpp.cpp +g++ -std=c++17 -o stl module8_stl_cpp.cpp + +# Ausführen +./memory +./datastruct +./oop +./stl +``` + +## Makefile + +```makefile +CXX = g++ +CXXFLAGS = -std=c++17 -Wall -Wextra + +all: memory datastruct oop stl + +memory: module1_memory_cpp.cpp + $(CXX) $(CXXFLAGS) -o $@ $< + +datastruct: module5_datastructures_cpp.cpp + $(CXX) $(CXXFLAGS) -o $@ $< + +oop: module7_oop_cpp.cpp + $(CXX) $(CXXFLAGS) -o $@ $< + +stl: module8_stl_cpp.cpp + $(CXX) $(CXXFLAGS) -o $@ $< + +clean: + rm -f memory datastruct oop stl + +.PHONY: all clean +``` + +## Hauptunterschiede C vs C++ + +| Aspekt | C | C++ | +|--------|---|-----| +| Speicher | malloc/free | new/delete, Smart Pointers | +| Datentypen | struct, primitive | class, string, vector, etc. | +| Generics | void* | templates | +| Fehlerbehandlung | Return codes | Exceptions (optional) | +| OOP | Manuell (Function Pointer) | Nativ (class, virtual) | + +--- + +**Empfohlene Lernreihenfolge:** +1. C-Modul durcharbeiten +2. C++-Vergleich anschauen +3. Unterschiede notieren +4. C++-Version selbst modifizieren