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)
Well, it's a syntax error, so that's why you're getting an error.
A start would be to remove the space between the underscores; the underscores are part of the identifier (name) __UNIQUETITLE_H.
Note that even if the space between the underscores was removed, it's still not entirely correct because any identifiers which contain two underscores in any position are always reserved names.
the thing is if I have only one header file it works fine. When I include more *.h files it starts to give me some errors, but the headers have different names ... i felt I needed to put it out there.
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.