confuse about included files

This is a discussion on confuse about included files within the C++ Programming forums, part of the General Programming Boards category; Hi, I am totally confused between include header files and source files? Some sample C++ programs in my C++ textbook ...

  1. #1
    C-Dumbie
    Guest

    Question confuse about included files

    Hi,
    I am totally confused between include header files and source files?
    Some sample C++ programs in my C++ textbook using like this:

    Code:
     
    #include <iostream.h>
    #include "Person.h"
    
    int main()
    {
       ........................
    }
    Other files such as Student.h using include like this:
    Code:
    const int MAX = 30;
    
    class Student
    {
       public:  
            Student();
            Getname();
            .......................
       private:
           char name[MAX];
           ............................
    };
    
    #include "Person.cpp"     //include source file at the end?
                                            //I am confuse??What the purpose here

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    #include can be used to include any type of file. You really should not #include a cpp file at the end of a header, however -- avoid it. The reason people often do #include a cpp file is so that the same header file can be included in multiple projects and they get both the declarations and the definitions whenever someone includes it. In reality, this is better done using a static link library instead. If you're not sure what's going on with the #include's then just imagine that a #include actually copy and pastes all the data from the file you are including into the file you include it from.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    one reason for #include'ing source files at the end of header files is so that the source file of the class need not be included in the project. The file just needs to be located in the same folder (if it is included like this: #include "file.h"), but if #include file.cpp is not in the header file, then you will have to include file.cpp in your project along with main.

    I'm sure this really doesn't touch the surface of #include'ing files at the end. I agree with polymorphic, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  2. Including kernel header files
    By carmaa in forum C Programming
    Replies: 0
    Last Post: 02-03-2008, 02:43 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Many Header Files
    By matth in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2005, 01:45 PM
  5. compiler won't find the included opengl files
    By cerin in forum C++ Programming
    Replies: 2
    Last Post: 03-05-2005, 11:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21