Senario:
There are two source files a. cpp and B. cpp both in a project. A. cpp between des a function called viod show (). Now I wanna invoke that function in B. cpp.
As I know, there are two ways we can use to invoke a function from another. cpp source file:
1. In B. cpp, use "extern void show ()" statement to declare an extern function.
2. Add a new header file (we call a. h for example), in that header file, we declare that function we want other source files to see and use by adding these codes:
# Ifndef a_h <br/> # definea_h <br/> void show (); <br/> # endif
Then, we need to add "include". H "" statement at the beginning of B. CPP, after "include <iostream>" statement. after that, we can invoke show () in B. CPP now.
PS: there is no restriction about the name of the header file, I use "B. H "as its name here is just to say that the function has ded in it is defined in. CPP file.
PPS: Does anyone know the differences between these two methods?