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 183 views
1 answer 191 views
1 answer 198 views
1 answer 200 views
1 answer 140 views
...