Thread: Beginner Question: Multiple source files

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    19

    Beginner Question: Multiple source files

    Hi people

    I got a C++ book and some of the example had multiple .cpp and .h files.

    Can someone explain how that works as the book didnt explain very well. How can you have multiple cpp files? I looked in the code and there didn't seem to be any reference to the other ones but they were all from the same program. They had different functions in that the program needed.

    Anyone?

    Thanks

    Ironfistchamp

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    FAQ > How do I... (Level 2) > Multiple source files for one program (C++ example)

    If you are using an IDE, you typically just add the .cpp module files to the project.

    [edit]And if you're using a makefile, you're in your own special hell until you've gotten the make utility somewhat figured out.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    19
    Thanks makes more sense now.

  4. #4
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    #include "filename.cpp"

    ?

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by divineleft
    #include "filename.cpp"

    ?
    No, no, no, no, no!
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    19
    No? What is wrong with that? Sorry must sound incredibly stupid but you don't learn if you dont ask.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by ironfistchamp
    No? What is wrong with that? Sorry must sound incredibly stupid but you don't learn if you dont ask.
    That's the path toward linker errors.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    oops.

    thats what i do

    I have lots of projects where I include at least 20 different things and it works fine. I just use it for better organization

  9. #9
    Registered User
    Join Date
    Jun 2006
    Posts
    19
    OK I shall not do that then. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Splitting source into multiple files(Linux & make)
    By IceDane in forum C Programming
    Replies: 6
    Last Post: 05-18-2009, 07:31 AM
  2. Mutex across multiple source files
    By Quasar in forum Linux Programming
    Replies: 7
    Last Post: 12-04-2007, 08:25 AM
  3. pseudocode for multiple source files
    By Calef13 in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2007, 09:07 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Mutiple source files for one program
    By earth_angel in forum C Programming
    Replies: 7
    Last Post: 06-08-2005, 09:47 AM