Lets consider the general case. A program contains 2 functions A and B. Each function must call the other. This is an example of recursion. More specifically, it is an example of what is called "Direct Recursion", where A calls B and B calls A. (In "Indirect recursion", A calls B, B calls C and C calls A, completing the recursive call).
Of course in recursion, there must be some way to terminate the recursion; else the program would end up in an infinite loop. To prevent this, the functions must include a terminating decision - which calls the other function only if a condition is satisfied.
The question is how to declare and define the functions. In C++ (and C), each entity must be declared before it is used. A definition is itself a declaration. But if A calls B and B calls A, we have a problem. One function call would occur before the compiler sees its declaration.
The solution is to declare the functions separately, before they are defined:
1 2 3
|
/// declarations ...
void A();
void B();
|
Then, include the definitions:
1 2 3 4 5 6 7 8 9 10 11
|
/// definitions ...
void A()
{
/// ...
}
void B()
{
/// ...
}
|
Then, the compiler sees the declarations of all functions, before either is invoked and so won't issue a compilation error.