Open Miaozu-Humphrey opened 4 years ago
Hi, this statemets are to include header only one time if other classes include same header
I admit that the way I used the header files here are a bit overkill. Because the compiler will only complain about duplicate definitions and not duplicate declarations. At the time I made these exercises I was still pretty new to c++ and was following best practices very strictly.
You can find a detailed explanation about header guards here: https://www.learncpp.com/cpp-tutorial/header-guards/
And in case you still have questions about why we need header files: https://www.learncpp.com/cpp-tutorial/header-files/
ifndef and #define are preprocessor symbols, preprocessing is a step that happens before compilation and consists of mostly textual substitution. The way they are used here is commonly called a header guard. Cause they prevent the header content from being included more than once in another source file.
I admit that the way I used the header files here are a bit overkill. Because the compiler will only complain about duplicate definitions and not duplicate declarations. At the time I made these exercises I was still pretty new to c++ and was following best practices very strictly.
You can find a detailed explanation about header guards here: https://www.learncpp.com/cpp-tutorial/header-guards/
And in case you still have questions about why we need header files: https://www.learncpp.com/cpp-tutorial/header-files/
I really appreciate that you can answer. I understand header guard now. And your reference website is amazing! Thank you!
@AartiKushwaha your Domain Registrar is Go Daddy, LLC
https://github.com/orgs/community/discussions/109171 Frauds happening everywhere
I am a new C++ learner following Accelerated C++ and very grateful for your solutions. I can understand most parts of your code. But I am still confused about header files. What do these #ifndef or #define statements mean? You write header for every CPP file and I can't find out why we need them. Could you explain these header files please and why we need them?
ifndef GUARD_0_3_H
define GUARD_0_3_H
void ex0_3();
endif // !GUARD_0_3_H