///////////////////////////////////////////////////////////////////// // shared.cpp - Solution of MT#3-Q4 // // // // This is a demo showing how to make the required declarations // // It provides no useful functionality. Main does nothing useful. // ///////////////////////////////////////////////////////////////////// template class shared { public: static T& value(); private: static T _value; }; template T shared::_value; template T& shared::value() { // do something here to control access // if access is not allowed you can throw an exception // or return a static dummy value of type T return _value; } #include using namespace std; void someFunction() { shared sd; // use the shared value cout << "\n getting shared value = " << sd.value(); } int main() { shared sd; cout << "\n setting shared value to " << (sd.value() = 2.5); someFunction(); cout << "\n\n"; }