Thread: Multiple C++ Files

  1. #1
    Registered User Sekti's Avatar
    Join Date
    Feb 2002

    Multiple C++ Files

    If I had two source files main_1.cpp and main_2.cpp would I be able to call functions defined in main_1 inside of main_2 or why would I use two I read something somewhere its better orgination but I'm not sure exactly.
    + Sekti

  2. #2
    you sure can...

    just remember that you can only have one function named main..
    check out this sample.....


    #ifndef MAIN1_H
    #define MAIN1_H

    int multiply(int x, int y);
    int addex(int x, int y);

    ////end of main1


    #include "main1.h"
    #include "main2.h"

    int multiply(int x, int y)
    return x * y;

    int addex( int x, int y)
    return add( x, y);

    #ifndef MAIN2_H
    #define MAIN2_H

    int add(int x, int y);

    /////end of main2

    #include "main2.h"

    int add(int x, int y)
    return x + y;


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-25-2008, 06:35 AM
  2. need assistance with multiple files
    By c++.prog.newbie in forum C++ Programming
    Replies: 7
    Last Post: 03-21-2006, 01:44 AM
  3. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 01:56 AM
  4. copy multiple files to a destination file
    By Bones in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 10:47 AM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 09:57 PM