Why template classes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?

21st Jan 2017, 10:01 AM
NOMNOM “The sadist 2.0”
NOMNOM “The sadist 2.0” - avatar
1 Answer
0
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.
31st Jan 2017, 12:34 PM
~datell