I have recently started to expand a small program I have written a few days ago and I need to include more header files to improve its readability. However, whenever I use the method I have been shown to in my course it gives some awkward error. I decided to use "#pragma once" instead because my compiler supports it, but I am still curios why the method I was using was not working.
Can someone explain me first what are the two "_ _" in front of the title (I have seen that some use one others are not using any) and why would this give an error (the functions that I use that finds themselves in one of the header files say they are not defined)
This is a syntax error because of the space between the two underscores. #ifndef expects a single identifier; here _ and _UNIQUETITLE_H are two different identifiers. #ifndef A_SINGLE_IDENTIFIER is equivalent to #if !defined(A_SINGLE_IDENTIFIER)
The identifier used as the guard (it is in the global namespace) should not begin with an underscore and should not contain a double underscore.
Some identifiers are reserved for use by C ++ implementations and shall not be used otherwise; no diagnostic is required.
— Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.
— Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.