Software Engineering: #include and header
Is there a convention "clean" or at least more logical than others, with regard to includes files in the header?
I used to declare functions/classes/structures in separate files (.hh. Hxx) of their implementation (.cc), but I can never determine from one project to another what is the cleanest namely putting all the necessary includes the declaration in the headers, or put them in .cc which means to make local definitions in the empty headers ("Class foo;" for example). And how to manage it?
With templates it becomes even more complex, what are the basic rules with classes and include templates?
Please help me!
Re: Software Engineering: #include and header
Quote:
Is there a convention "clean" or at least more logical than others, with regard to includes files in the header?
I do not know if there are 'agreements' or practices. Through my experiences, I have seen various cases, so I tend to think not.
Quote:
I used to declare functions/classes/structures in separate files (.hh. Hxx) of their implementation (.cc), but I can never determine from one project to another what is the cleanest namely putting all the necessary includes the declaration in the headers, or put them in .cc which means to make local definitions in the empty headers ("Class foo;" for example). And how to manage it?
I separated my statements (.h) of my definitions (.cpp). In the header files .h, I expected statements (class foo;) as soon as I can and I did that include in the .cpp.
In the source file, I include the header files in this order:
1. The header file for the declaration of the class
2. The header files of my project
3. The header files of my external libraries
4. The header files for third-party libraries (boost, xml, windows, wxWidgets, ...)
5. Files standards (stl).
In case of precompiled headers, I try to benefit from precompilation up putting the headers of external libraries and third in the precompiled header which changes the order presented above.
Re: Software Engineering: #include and header
Quote:
With templates it becomes even more complex, what are the basic rules with classes and include templates?
For simple templates, all in the same file .h. For more complex templates, do not hesitate to separate declaration and definition. Also separate when a template based on classes/or other policies occurs.
I would add that the statements .hpp are necessary. Because it prevents the class included to be visible in the other file when you include it in .hpp. Moreover, it is possible that there are conflicts (including twice the same function) without this technique.
Re: Software Engineering: #include and header
Quote:
I separated my statements (.h) of my definitions (.cpp). In the header files .h, I expected statements (class foo; ) as soon as I can and I did that include in the .cpp.
That's what I tend to do, the big problem is with the templates.
Quote:
For simple templates, all in the same file .h. For more complex templates, do not hesitate to separate declaration and definition. Also separate when a template based on classes/or other policies occurs.
Personally, I assume that files class declaration should contain only the headers and documentation.
With of course a single class per file. Otherwise it was quick to get lost.
Quote:
Moreover, it is possible that there are conflicts (including twice the same function) without this technique.
I do not see how that is possible when you use the technique:
Code:
# ifndef foo_HH
#define foo_HH
/ / / ...
# endif / *!foo_HH * /