What is overloading template?
Submitted by: AdministratorA 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;
}
Submitted by: Administrator
#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;
}
Submitted by: Administrator
Read Online C++ Operator Overloading Job Interview Questions And Answers
Top C++ Operator Overloading Questions
☺ | Pick the other name of operator function. |
☺ | What is overloading template? |
☺ | Can you please explain the difference between overloaded functions and overridden functions? |
☺ | Explain overloading unary operator? |
☺ | Can you please explain function overloading? |
Top C Plus Plus Language Categories
☺ | C++ Pointers & Functions Interview Questions. |
☺ | C++ Operator Overloading Interview Questions. |
☺ | C++ Exception Handling Interview Questions. |
☺ | C++ Virtual Functions Interview Questions. |
☺ | C++ Template Interview Questions. |