Add C++ example: README.md

This commit is contained in:
2026-04-15 00:18:28 +02:00
parent 30c1204062
commit 229973910d

View File

@@ -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