Results 1 to 4 of 4

Thread: Software Engineering: #include and header

  1. #1
    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!

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: 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 do not know if there are 'agreements' or practices. Through my experiences, I have seen various cases, so I tend to think not.

    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.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Software Engineering: #include and header

    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.

  4. #4
    Join Date
    May 2008
    Posts
    976

    Re: Software Engineering: #include and header

    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.

    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.

    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 * /

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,695,712.01704 seconds with 17 queries