- 1
What are the advantages of using templates in C++?
3 ответов
+ 7
By using templates we can implement different data types .
Instead of using any particular data type we can use a template and then later convert it into any data type we want.
+ 3
Not worried much about overloading, like
template <typename T>
T m(T x, T y){
return (x>y)?x:y;
}
int main() {
cout<<m<int>(1,3)<<endl;
cout<<m<char>('x','X');
return 0;
}
I'm sure there are some more
+ 2
Template are inline and such as your template code will not use function call but it will be "expanded" at compile time with right types by compiler (its not a real advantage in all case but its useful to know)