How to initialize static member in a template struct using C++

1 Answer

0 votes
#include <iostream>
#include <cstring>

using std::cout;
using std::endl;

template <typename T>
struct Test
{
	static double s;
};

template <typename T>
double Test<T>::s = 3.14;

int main()
{
	Test<double> od;

	cout << od.s << endl;

	return 0;
}



/*
run:

3.14

*/

 



answered Mar 14, 2018 by avibootz

Related questions

1 answer 194 views
1 answer 197 views
1 answer 209 views
1 answer 210 views
1 answer 146 views
...