How to write template class with generic parameter in C++

1 Answer

0 votes
#include <iostream>

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

template<class T> class Test {
public:
	Test(T a) { Test::a = a; };
	void print(void) {
		cout << a << endl;
	};
private:
	T a;
};


int main(void)
{
	Test<int> int_o(9999);
	Test<long> long_o(888888888L);

	int_o.print();
	long_o.print();

	return 0;
}

/*
run:

9999
888888888

*/

 



answered Mar 14, 2018 by avibootz
edited Mar 14, 2018 by avibootz

Related questions

1 answer 237 views
2 answers 267 views
1 answer 234 views
1 answer 191 views
1 answer 258 views
1 answer 241 views
...