Avatar ·

Wozu braucht man #ifndef und #define in C++-Headerdateien?

Hallo zusammen! Ich habe gerade angefangen, C++ zu lernen, und schreibe mein erstes Programm, das aus mehreren Dateien besteht. Ich habe drei Dateien: `main.cpp`, `functions.h` und `functions.cpp`. Hier ist der Inhalt von `functions.h`: ```cpp // functions.h void printHello(); int add(int a, int b); ``` In `functions.cpp` binde ich diese Headerdatei ein und definiere die Funktionen: ```cpp // functions.cpp #include "functions.h" #include void printHello() { std::cout << "Hello, world!" << std::endl; } int add(int a, int b) { return a + b; } ``` Und in `main.cpp` binde ich ebenfalls `functions.h` ein: ```cpp // main.cpp #include "functions.h" #include int main() { printHello(); std::cout << add(3, 4) << std::endl; return 0; } ``` Alles funktioniert. Aber ich habe bemerkt...