Xcode c++ and simplicity

Hi,



I'm a mac user and I'm making a basic text-based c++ program. Now I would like to get more complex, and make my code easier to read by having multiple .c++ files. I'm going to have a main one that says something like control panel, and you'd type what you'd want to do which would link to my various programs I've written. I just don't know how to link to another C++ source file within the same program. I'm using mac OS X 10.6.8 with Xcode 3.2.6. Thanks in advance.
I don't know Xcode 3.2.6 but from google I noticed it's an IDE I guess.

Well the normal approach is to add more files to your project by some way (I cannot help you on how for your program but shouldn't be too complicated) and just compile it.

Basically you always start by your main.cpp. In there you include your custom header files (.h), e.g. circle.h.
Of course you should have written the header file.

Inside a header file you can put what ever you like an by that I mean your functions, classes etc, but normally and to keep with c++ designing rules you just put your function, classes declaration (that is your prototypes e.g. void setDiameter(double d);).

No for each of your functions/classes you should provide an implementation (that is definition). This normally goes to your cpp files (e.g. circle.cpp).

In other words inside some header file you put what your funtions/classes should do and inside your source file how this is going to happen.
In XCode 3.2.6, to add a new source file to your project, right-click (or ctrl-click if you have a single button mouse) on your project in the "Groups & Files", choose "Add", "New File".

Choose "C and C++" from the list on the left, then choose your file type from the right, either a C file, C++ file or a Header file.

Enter your filename and away you go. The file(s) will be added to your project and linked with the rest of your source files.
Last edited on
Topic archived. No new replies allowed.