fork(1) download
  1. #include <string>
  2.  
  3. namespace my_ns
  4. {
  5. namespace miruna
  6. {
  7. template<typename T>
  8. struct static_vars_holder
  9. {
  10. static int i1;
  11. static double d1;
  12. static std::string s1;
  13. };
  14.  
  15. template<typename T>
  16. int static_vars_holder<T>::i1 = 100;
  17.  
  18. template<typename T>
  19. double static_vars_holder<T>::d1 = 123.45;
  20.  
  21. template<typename T>
  22. std::string static_vars_holder<T>::s1 = "test string";
  23.  
  24. template
  25. struct static_vars_holder<void>;
  26. }
  27.  
  28. typedef my_ns::miruna::static_vars_holder<void> static_vars;
  29.  
  30. namespace
  31. {
  32. int & i1 = static_vars::i1;
  33.  
  34. double & d1 = static_vars::d1;
  35.  
  36. std::string & s1 = static_vars::s1;
  37. }
  38. }
  39.  
  40. ///////////////////////////////
  41.  
  42. #include <iostream>
  43. using namespace std;
  44. int main()
  45. {
  46. cout << my_ns::i1++ << endl;
  47. cout << my_ns::d1++ << endl;
  48. cout << my_ns::s1 << endl; my_ns::s1 += "...";
  49.  
  50. cout << my_ns::static_vars::i1 << endl;;
  51. cout << my_ns::static_vars::d1 << endl;;
  52. cout << my_ns::static_vars::s1 << endl;;
  53. }
  54.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
100
123.45
test string
101
124.45
test string...