模板中的静态模板变量 class

static template variable in template class

我想定义模板化的静态模板变量class。但是我在这里找不到正确的语法:

template < typename T>
class X
{
    public:
        T i;
        X(T _i): i{_i}{}

        operator T(){ return i; }
}; 

 template < typename T2 >
 class Y
 {
     public:
         template <typename T>
             static X<T> x_in_y;
 };

 // something like that, which currently do not compile     
 template< typename T2, typename T>
 X<T> Y<T2>::x_in_y<T>{9.9};

 int main()
 {
      std::cout << Y<int>::x_in_y<float> << std::endl;
 }

x_in_y是模板中的模板所以你需要一个嵌套的模板声明:

template<typename T2>
template<typename T>
X<T> Y<T2>::x_in_y{9.9};