Quantcast
Channel: Go4Expert
Viewing all articles
Browse latest Browse all 1994

C++ Templates

$
0
0
Before we go into the details of C++ templates let us take an example of function overloading. I am assuming you know what is function overloading.

Code:
#include<iostream>
using namespace std;
int larger(int n1, int n2)
{
    cout << "int larger(int, int) is called" << endl;
    return n1 > n2 ? n1 : n2;
}
char larger(char n1, char n2)
{
    cout << "char larger(char, char) is called" << endl;
    return n1 > n2 ? n1 : n2;
}

int main()
{
    int n1{ 10 }, n2{ 20 };...
C++ Templates

Viewing all articles
Browse latest Browse all 1994

Trending Articles