I want to define the static template variable of a templated class. But I can't get the correct syntax here:
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
is a template in a template so you need a nested template declaration:
template<typename T2>
template<typename T>
X<T> Y<T2>::x_in_y{9.9};