Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Usually, the class definition is typically in your .h file, and the implementation is in your .c(pp) file. </p> <p>One advantage of doing <code>#include "a.h"</code> in your b.c file, rather than in your b.h file, is that whenever a.h changes, not only b.c but also any other file that includes b.h will have be recompiled. </p> <p>Also, you're kind of unnecessary exposing implementation details of B to anyone using b.h. The idea is that b.h should not contain additional info that is of no interest to someone using class B (not because it's secret, but because people don't care and you don't want to bother them with it).</p> <p>There's no need to force anyone including b.h, to indirectly include a dozen of other .h files as well (because they're #included in b.h), just because you happen to use that stuff in b.c. Avoid clutter. </p> <p><strong>So if possible, it's best to <code>#include "a.h"</code> in b.c !</strong></p> <p>But this is not always possible. If you're just using A inside b.c, and there are no references to A in b.h, then it's OK. Also, if b.h only contains pointers to A (i.e. as members, function arguments or return values) but no 'type dependent' references, you could also put just this in b.h:</p> <pre><code>class A; </code></pre> <p>And still keep <code>#include "a.h"</code> in your b.c. But if there are more references or dependencies on a.h, that anyone including b.h really couldn't do without, then <code>#include "a.h"</code> should go in b.h</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload