I wish to write a function template to find larger of the two numbers passed in as parameters. And I want to explicitly instantiate this function template for int
.
So I wrote in the larger.h the following;
template <typename T>
const T& larger(T a,T b);
I wrote in larger.cpp the following:
#include<iostream>
#include"larger.h"
const T& larger(T a,T b) {
return a<b?b:a;
}
In the main.cpp:
#include<iostream>
#include "larger.h"
int main(){
template int()
const& larger<int>(int,int);
std::cout << larger(6,8) << std::endl;
}
When I compile and try to run main.cpp,I get the following error:
error: expected primary-expression before ‘template’
template int()
I am unable to proceed further. What's wrong?