+ 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
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
2 Antworten
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
Solo Wanderer 4315
Solo Wanderer 4315 - avatar