What is overloading template? - C++

What is overloading template? Explain it with an example.

- A template function overloads itself as needed. But we can explicitly overload it too. Overloading a function template means having different sets of function templates which differ in their parameter list.
- Consider following example :
#include <iostream>

template <class X> void func(X a)
{
   // Function code;
   cout <<”Inside f(X a) \n”;
}

template <class X, class Y> void func(X a, Y b) //overloading function template func()
{
   // Function code;
   cout <<”Inside f(X a, Y b) \n”;
}

int main()
{
   func(10); // calls func(X a)
   func(10, 20); // calls func(X a, Y b)
   return 0;
}
Explain how we implement exception handling in C++.
Explain how we implement exception handling in C++ - Exception handling in C++ is implemented by using the try{} and catch(){} statements.....
Explain terminate() and unexpected() function - C++
Explain terminate() and unexpected() function - terminate() is a library function which by default aborts the program....
Describe Exception handling concept with an example
Describe Exception handling concept with an example - Exceptions are certain disastrous error conditions that occur during the execution of a program.....
Post your comment