[RESOLVED] About Including header files to source file or Header file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] About Including header files to source file or Header file

  1. #1
    Join Date
    Feb 2013
    Posts
    12

    [RESOLVED] About Including header files to source file or Header file

    Hi,


    For example, I have the below files in a project called Calculate :

    Source files : Calculate.cpp , Average.cpp (with out main)
    Header files : Calculate.h , Average.h

    I knew in general, we have to include Average.h to project header file Calculate.h to make it as part of project.


    Can anyone please explain me the technical difference between adding header file (Average.h) to either project header file (Calculate.h) or project source file (Calculate.cpp) ?

    I found no difference in an output. But, there must be technical difference. Looking forward to hear from you.

    Thanks in advance,
    Last edited by srvolatile; July 10th, 2013 at 12:43 PM.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,206

    Re: About Including header files to source file or Header file

    Quote Originally Posted by srvolatile View Post
    Hi,


    For example, I have the below files in a project called Calculate :

    Source files : Calculate.cpp , Average.cpp (with out main)
    Header files : Calculate.h , Average.h

    I knew in general, we have to include Average.h to project header file Calculate.h to make it as part of project.


    Can anyone please explain me the technical difference between adding header file (Average.h) to either project header file (Calculate.h) or project source file (Calculate.cpp) ?

    I found no difference in an output. But, there must be technical difference. Looking forward to hear from you.

    Thanks in advance,
    If you #include a.h in b.h, then any module that #includes b.h, also #includes a.h. Sometimes that's good, usually not. You want to reduce inter-dependencies when you can.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,444

    Re: About Including header files to source file or Header file

    Quote Originally Posted by srvolatile View Post
    I found no difference in an output.
    Header files in C++ are only used in the build process, not when you run your program. If the program builds correctly regardless of where the header files are included, the output will be the same.

    The only exception is if you're building a C program or C module. For the C language, header file inclusion or non-inclusiion can make a big difference in what output you see or how a program behaves.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Feb 2013
    Posts
    12

    Re: About Including header files to source file or Header file

    Thanks to both of you (@GCDEF, @Paul McKenzie) for your explanation.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center