Can I somehow input the type for a template class or function? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 10

Can I somehow input the type for a template class or function?

I have a generic Matrix Class which is finally working for all data types, except char. Is there a way I can input the data type in the console so as to customize the output everytime? Will using if else with strings or switch with cases be the only way? Is there NO way we can input data types? Pls help me...

23rd Apr 2017, 5:00 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
2 Respostas
0
I guess it's not possible, as C++ templates are type-safe, meaning that they're checked and expanded at compile time. That is, they must have specific types when compiling, thus making it not possible to depend on user's input.
25th Apr 2017, 5:58 AM
Ɓlvaro
+ 10
Thanks!
28th Apr 2017, 3:10 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar