Why template classes? | Sololearn: Learn to code for FREE!


Why template classes?

I understand why we use templates for functions, but what is the point of class templates? Can someone give me an example?

1/21/2017 10:01:48 AM

NOMNOM “The sadist 2.0”

1 Answer

New Answer


It just gives you the power to create very abstract classes without type dependency. Let's imagine you want to implement a class for big numbers in C++. It's obivous that this class should be if variable type. You could then create subclasses BigInt, BigDouble and so on all being based on one template base class.