Why template classes? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Resposta
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