118 Introduction to C++ Programming and Graphics
To circumvent this difficulty, we declare the variable in the second file as
external by issuing the statement:
extern int kokoras;which reassures the compiler that the value of this variable will be supplied
externally.
As an example, the main program contained in the filekotoula.cc, and a
function namedkalabokiare implemented, respectively, as:
#include <iostream>
#include "kalaboki.h"
using namespace std;int kokoras = 10;int main()
{
kalaboki();
cout << kokoras << endl;
return 0;
}and
using namespace std;extern int kokoras;void kalaboki()
{
kokoras++;
return kokoras;
}The header file of the functionkalaboki.ccis:
#ifndef KALABOKIH
#define KALABOKIHusing namespace std;
extern int kokoras;
void kalaboki();#endif