User Tools

Site Tools


c_-_c_templates:overloading_template_function

C - C++ Templates - Overloading Template Function

#include <iostream>
using namespace std;
 
template <class X> 
void f(X a)
{
  cout << "Inside f(X a)\n";
}
 
 
template <class X, class Y> 
void f(X a, Y b)
{
  cout << "Inside f(X a, Y b)\n";
}
 
 
int main()
{
  f(10);     // calls f(X)
  f(10, 20); // calls f(X, Y)
 
  return 0;
}
c_-_c_templates/overloading_template_function.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki