Multi source files in visual studio

Hi,
I already used more than one source file in my project for simple functions and everything compiled successfully.

Now I am trying to add another source file of a slightly more complex function.
This functions uses:

-global declared struct
-calls another function at the end
-uses a global variable int

What is the procedure step by step (header files, include's etc)to compile properly because I couldn't find anything for a slightly complicated function.
1. Make a header file for this source file.
2. Put the declarations for the applicable functions in this header file.
3. Define those functions in your source, the other source files can now use your function.
4. If you are using a function from another source file, include that source's header in your source.

5. If you use a global struct from another source file, ensure that you include that source's header
6. If you are making a global struct available for another source file, define it in your source and then declare it in your header with the extern keyword.

7. If you are using a global variable (int) from another source file, ensure that you include that source's header.
8. If you are making a global variable (int) available for another source file, define it in your source and then declare it in your header with the extern keyword.
Hi, thanks for the explanation I managed to follow.

Now I need to know if I have to do another header file for my original source file and what to include exactly in it?

Oki worked worked perfectly :)

Need to add:

-Never initialize variables in the new source file if they are already initialised in the main.cpp :)
Topic archived. No new replies allowed.