Is it just one big file of code or do you use many different files of code and "call" them in or something when needed? If anyone could point me to a link with any info about the setup of projects or anything I would appreciate it.
Is it just one big file of code or do you use many different files of code and "call" them in or something when needed? If anyone could point me to a link with any info about the setup of projects or anything I would appreciate it.
Well, it depends on the size of the project, of course.
The most basic programs obviously are nothing but a single .cc file.
Slightly more complicated programs structure things out, usually creating multiple .h files (containing declarations and maybe implementations of short classes/functions) and corresponding .cc file (implementations only), only one of which has a main() function. Some sort of project manager (depending on your compiler) separatately compiles each .cc and links them all together at the end. Of course, the files are dependent and one class may need to know of the existence of structures and functions in the other; so you use #include to include the declarations in the .h files.
The largest projects are structured similarly to this. From my experience working as an intern developing part of a large (8 year effort so far) software package in C++, each major class (there may be hundreds or more) is given its own .h and .cc files; the .h contains the class declaration and the .cc contains all the implementations. Related .h and .cc files are grouped in modules; for each of these modules there is a corresponding templates file containing explicit instantiations for templates needed by those classes (automatic instantiation is too slow for large projects). Since you typically have to include hundreds of files, there are also files created that are updated daily that save your compiler some of the effort of constantly recompiling low-level code. There is also of course required documentation for each class, and a required testing function. This particular project documents all its structure on the web; if you're curious check out http://www.aips2.nrao.edu/docs/aips/aips.html. The project code organization standards (the long version of what I wrote) are at http://www.aips2.nrao.edu/docs/refer...ng/node29.html.
Last edited by Procyon; 09-28-2001 at 06:30 PM.
Wow, nice run down. That makes alot of sence. I've heard of classes, declarations, and fuctions but I'm not sure what each means and where they would be found in a program. Using this code......would each of these be?Code:#include < stdio.h > #include < iostream.h > #include < conio.h > int main() { cout<<"Hello World!"; getch(); return 0; }
How is a C++ program broken down? Like most of us, I suppose. No specific thing, just the wearisome sameness, the endless repetition, the pressure to make choices or "else", trying to keep our private members out of the public. Then the same thing the next day, no matter how hard we "run". It's no wonder the programs break down.
The program below is actually a cpp file with a main() function, and is sometimes called a driver file/program. Only one cpp file in each program can have a main() function. This is the code your write. Your compiler/project software/IDE turns this file into a program that (likely) has an associated header file (which is probably a default file) somewhere and, depending on your compiler, probably has a bunch of other files associated with it too, like .ide, .obj, .mak, .csm, .exe, etc. which are generated by the compiler/project software when it changes the stuff you write into an executable file. Many compilers/progect managers/IDEs have switches to tell it what type of file you want it to make (.exe vs .dll vs lib) etc., but these options usually are used only after you have mastered the basic syntax of C/C++.
The following code lines are all precompiled header files container (primarily) function declarations and some inline functions. You can create your own header files and include them here, too. Each header file (usually) is associated with an associated .c or .cpp or .cc file or library file (.lib extension) (.dll files fit in here someplace too) that contain the function definitions for all the functions listed in the header files. Note you don't have to (and shouldn't) list any of the associated cpp file for the header files included in this program.
--------------------------------------------------------------------------------#include < stdio.h >
#include < iostream.h >
#include < conio.h >
----------------------------------------------------------------------
//here's the code to actually run the program
int main()
{
cout<<"Hello World!";
getch();
return 0;
}
This program has no user defined functions or classes/structs/types. If it did, the user defined function prototypes and class declarations (or other user defined types like enums, typedefs, structs, etc.) would routinely be listed after the includes and before main(), unless they were compiled into a separate header so they could be reused in another project someday. The function definitions and class methods are commonly placed after main(), although you will see them between the includes and before main(), but after any pertinent declarations/prototypes, too. Either way works and is more a personal style than anything. If the function and class declarations are in a header file, the definitions will usually be in the associated cpp file (although they could be in a .lib or .dll file too).
well the #includes are the Header files which hold all the prototypes of the meathods you are going to call apon
eg to use the cout function you have to have #include <iostream>
other wise the compiler dosent know what your talking about.
and as for the getch();, its not even needed... try it with out that
So if for example, I was creating a math test program (which would ask you random math questions). I could create a file called "Numbers.h" and declare the numbers? Example
So I could just add this header file ("Numbers.h") into the preprocessor and it would automaticly know what I mean when I say "N1+N2" and so on?Code:N1=2 N2=4 N3=6
Is the function the part of int main()? Is that the only function or are there more (it's the only thing I've seen so far, still new )? What what is inside the { } have to be declared under the #included header file for it to compile and execute?
Thanks for the help!