Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Initializing static member of nested templated class during nested template specialization?
  2. template<typename T>
  3. class Outer
  4. {
  5. public:
  6.     template<typename U>
  7.     class Inner
  8.     {
  9.     private:
  10.         static int count;
  11.     };
  12.  
  13.     static int code;
  14.     void print() const
  15.     {
  16.         std::cout << "generic";
  17.     }
  18. };
  19.  
  20. template<>
  21. template<>
  22. class Outer<bool>::Inner<bool>
  23. {
  24.     static int count;
  25. };
  26.  
  27. template<>
  28. template<>
  29. int Outer<bool>::Inner<bool>::count = 4; // ERROR
  30.        
  31. int Outer<bool>::Inner<bool>::count = 4;
  32.        
  33. template<typename T>
  34. class Outer
  35. {
  36. public:
  37.     template<typename U>
  38.     class Inner
  39.     {
  40.     private:
  41.         static int count;
  42.     };
  43.  
  44.     static int code;
  45.     void print() const
  46.     {
  47.         std::cout << "generic";
  48.     }
  49. };
  50.  
  51. template<typename T>
  52. int Outer<T>::code = 0;
  53.  
  54. template<typename T>
  55. template<typename U>
  56. int Outer<T>::Inner<U>::count = 0;
  57.  
  58. template<>
  59. template<>
  60. class Outer<bool>::Inner<bool>
  61. {
  62.     static int count;
  63. };
  64.  
  65. int Outer<bool>::Inner<bool>::count = 4;