Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Multiple Read Protection [#ifndef – 2] What if we have, say, 4 class headers being stored in one file, for convenience. Would we use ONE #ifndef directive or MULTIPLE #ifndef directives around each individual class header?

[#ifndef class headers read stored
0
Posted

Multiple Read Protection [#ifndef – 2] What if we have, say, 4 class headers being stored in one file, for convenience. Would we use ONE #ifndef directive or MULTIPLE #ifndef directives around each individual class header?

0

You would just protect the whole file. The purpose of a header file inclusion is to supply defintions of classes or functions to a client program. This does not “bulk up” the executable, it just provides information used in the compile process. Thus there is no harm in over-supplying definitions. Of course, you could go overboard with this, throwing hundreds of class defintions into one file, then the compile process would get noticably slowed by packing the (temporary) symbol table with unneeded terms. Good design will prevent such excesses by having only a collection of related classes defined in the same file.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123