c++ - Should I include every header? -


Should I include every headers, even if it has been included earlier? Or maybe I can avoid it when I can? for example. If I use std :: string and std :: vector in some file if & lt; String & gt; contains & lt; Vector & gt; Only me & lt; String & gt; or & lt; String & gt; and & lt; Vector & gt; ?

If you use a header related unit (for example some type) in the file, you For this, the respective headers should be included. Do not trust the header to include each other. If you use it, include it .

C ++ Standard Library & lt; String & gt; in & lt; Vector & gt; ; And in contrast to using such functionality, the code will be limited to a specific implementation. In general, standard library headers can not include or include other headers (or their own internal headers) in an unspecified order or way is a notable exception & lt; Initializer_list & gt; which needs to be included in any may also change in this unspecified order or method, thus breaking the first compilation code with an updated compiler or an updated standard library implementation (to go to this ) .

Assume that if the header file is defined by the class, then it must include what is necessary for the definition of that class. Associated in .cpp , its associated code should include the .h and the rest of the files needed to implement the class. This is not required, do not include it ; There is more than not included () An exception is here; This exception will apply to other headers only on implementation.

It is noted that maintenance of you are involved in can be difficult in a long time; Thus it is important to understand what is necessary for the interface to be included at the beginning of the coding cycle; And then to check again it is included with any appropriate changes made to the code.

There may be some progress w.r.t. In this regard, the tool uses the clag tool series and also looks for MSVC

will be a counter example if the header causes the other headers to be included It may be, but still I will be very careful - make sure that it is clearly defined. An example might be a precompiled header


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -