Is it possible to limit the number of times a header file is called in the project?
Yes, if the quantity is 1. More than that you would need auxiliary tools, but it does not make sense, you do not have to enter 2 times.
Do you recommend using the "#pragma once" directive?
In the compilers that accept , yes, I prefer its use. Not everyone accepts and prefers other mechanisms that do the same. I think preciosismo in the present stage. In general, true C or C ++ programmers are above average, but I see many having these things to follow cake recipe without looking at the context.
For example, the file a.h
includes a1.h
and a2.h
and is included by b.h
and b.h
needs a1.h
, do I have to implicitly call them b.h
? Is not it enough that they are already called in a.h
?
No need. Under normal conditions it will already be included and this is even the reason why pragma once
exists. You could include it to ensure you do not risk going in twice.
You can do some nonsense and make the second entry be processed differently, but I do not recommend this, even if it has some use.