#### Archived

This topic is now archived and is closed to further replies.

# A VERY Simple Question about COMPILING

This topic is 6324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Example: I have file1.cpp and file2.cpp. In file1.cpp i have make a function called ''Function1''. Now, file2.cpp uses this function in its code, but problem is that the complier compiles file2.cpp before file1.cpp, and so the compiler compains about function1 not being declared. At the moment i am creating prototypes to shut up the compiler (e.g. putting function1''s prototype into file2.cpp so that it knows it exists). Is there a way around this?? Im using Visual C++. Or is there a Technique? Thanks.

##### Share on other sites
Ok this is what you do. Make a header file and put the function declarations in it. Then in one of your cpp files, include that header and type the function definitions. Now, if you include that header file in any cpp, your functions will work fine.

Snyper

##### Share on other sites
Yes, that is what you want to do. Let me expand on this further: For every cpp file, there should usually be an accompanying .h file with all the function definitons in it. I'm fairly sure this is common design practice (I'm about 98% sure that 90% of coders do this). You'll also want to make sure the .h can only be included once using something along the lines of:
#ifndef HEADERNAMESOMETHING#define HEADERNAMESOMETHING//blah..#endif

You could also use '#pragma once', but this may not work with compilers other than MSVC (which is probably something you're not worried about at this point anyway )

Edited by - A. Buza on October 30, 2000 11:49:30 PM