Multiple C++ Files

This is a discussion on Multiple C++ Files within the C++ Programming forums, part of the General Programming Boards category; 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 ...

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

    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
    Unregistered
    Guest
    you sure can...

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

    //-------------------------
    //main1.h

    #ifndef MAIN1_H
    #define MAIN1_H

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

    #endif
    ////end of main1

    //--------------------------
    //main1.cpp

    #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);
    }

    //-------------------------main2.h
    #ifndef MAIN2_H
    #define MAIN2_H

    int add(int x, int y);

    #endif
    /////end of main2




    //---------------------------
    //main2.cpp
    #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, 05:35 AM
  2. need assistance with multiple files
    By c++.prog.newbie in forum C++ Programming
    Replies: 7
    Last Post: 03-21-2006, 12:44 AM
  3. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 12: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

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