Thread: Multi File Projects

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

    Multi File Projects

    I'm looking for possible help or tutorials about using a
    Multi File Source Code, the whole program uses each other's
    variable so there isn't such thing as an alone class (that's easy
    to seperate)

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Do you mean a procedural C style design? Consider #include.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I know how to include and link etc.
    I want to know how to combine different c++ sources,
    with the declarations in the headers,
    And how to connect them, i know how to do that as well
    but only if they don't use each other's variable, that's
    what i want to accomplish

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Lightbulb

    I think i´ve seen #include in some source codes. Consider you have three separate files: main.cpp vars.cpp and functs.cpp. In main.cpp you have the main() function, in vars.cpp you have all the variables and in functs.cpp you have all the other functions you need for your program. You could write this at the heading of the main.cpp file:
    Code:
    #include functs.cpp //file with the functions
    #include vars.cpp //file with the variables
    
    main()
    {
    // the rest of the code here...
    }
    I think that should work.

    Just the thoughts of a C++ newbie...

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    That's not the way you should use CPP files, ive intregrated them
    into my project and thus linking it together with other sources,
    But i just need a tutorial on using multi file sources, it arent just
    peaces of code that i 'add' in my source they all cooperate

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I'm confusing, i'l explain more clearly,
    The actual problem is that the header of CLASS1 includes
    all the global variables and the MAIN header includes them
    as well and there's problem

    error LNK2005: "" (?error LNK2005: "float * " (?@@3PAMA) already defined in Main.obj@@3_NA)
    already defined in Main.obj

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    What is your design? Post an example of what you want to implement.

    Kuphryn

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Oke, how can i get CLASS1.cpp to use MAIN.cpp variables?

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Class1 have no knowledge of local variables in main by design.

    Kuphryn

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    New explanation!!!

    I have:

    Monkey.ccp
    // includes monkey.h and main.h
    Monkey.h
    // declarations od the class monkey
    Main.ccp
    // has main, includes main.h and monkey.h
    Main.h
    // Containts global variables

    This results is

    error LNK2005: "int bla@@3HA) already defined in Main.obj

    So i need to use the variables in main.h in main.cpp and
    monkey.cpp, however if main.cpp is compiled main.obj contains these, and if monkey.cpp compiles, it errors up
    saying that main.obj alerady has these! how can i get monkey.cpp to use main.cpp's variable's?

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Figured it out already ,
    Thx for the reply's anyhow

    Close me

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Figured it out already
    I take it you found the extern keyword then!

    Also, you shouldn't #include source files (.cpp), only header files (.h).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I know i know, i dint suggested that, and indeed it was extern

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. file processing updating record error
    By uuser in forum C Programming
    Replies: 2
    Last Post: 04-27-2003, 12:13 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM