Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Keyword to make a variable known over multiple units, but keeping the declaration and initialization local to a file (probably an implementation file (.cpp))
In the example below there are two integer globals (note: avoid using global data [1,2]). The int x is declared and initialized in unit1.cpp, the int y in declared in unit2.cpp and initialized by the locally unknown int x. To read the values of both integers, two getters are put in the header files.
#include <cassert> |
#ifndef Unit1H |
#include "Unit1.h" |
#ifndef Unit2H |
#include "Unit2.h" |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.