Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-05-2009
Member
 
Join Date: May 2008
Posts: 976
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!
Reply With Quote
  #2  
Old 06-05-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 06-05-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #4  
Old 06-05-2009
Member
 
Join Date: May 2008
Posts: 976
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 * /
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Software Engineering: #include and header"
Thread Thread Starter Forum Replies Last Post
Being in the Indian Software Engineering industry patriot77 Education Career and Job Discussions 1 14-05-2012 12:02 PM
Connect USB 3.0 front case panel header to motherboard w/o a header? Dogs-Day-Out Motherboard Processor & RAM 4 14-04-2012 07:02 PM
Details of Data Recovery Engineering Software Sib Bachchan Windows Software 4 20-02-2012 04:02 PM
How to include Header & footer within HTML? seema_thk Software Development 3 09-12-2009 09:24 AM
What is the difference between Computer Engineering and Software Engineering Paramartha Education Career and Job Discussions 4 25-09-2009 04:16 PM


All times are GMT +5.5. The time now is 09:04 PM.