// ------------------------------ // Main.cpp #include #include "Test.h" #include "First.h" #include "Second.h" #include "Third.h" using namespace std; int wmain(int argc, wchar_t ** argv) { Test test; First first; wcout << test.get_HiddenGlobal() << endl; Second second; wcout << test.get_HiddenGlobal() << endl; Third third; wcout << test.get_HiddenGlobal() << endl; wcout << third.get_HiddenGlobal() << endl; return 0; } // ------------------------------ // Test.h #pragma once namespace { int hiddenGlobal; } class Test { public: int get_HiddenGlobal() const { return hiddenGlobal; } void set_HiddenGlobal(int value) const { hiddenGlobal = value; } }; // ------------------------------ // First.h #pragma once #include "Test.h" class First { public: First() { Test test; test.set_HiddenGlobal(1); } }; // ------------------------------ // Second.h #pragma once #include "Test.h" class Second { public: Second() { Test test; test.set_HiddenGlobal(2); } }; // ------------------------------ // Third.h #pragma once #include "Test.h" class Third { public: Third(); int get_HiddenGlobal() const; private: Test test_; }; // ------------------------------ // Third.cpp #include "Third.h" #include "Test.h" Third::Third() : test_() { test_.set_HiddenGlobal(3); } int Third::get_HiddenGlobal() const { return test_.get_HiddenGlobal(); }