M
Michael DeWulf
Just to help my understanding, what is supposed to happen on a template
function or class when the user does not specify the template type?
GCC reports that the code below is using min_t with the form:
N min_t(N, T) [with N = int, T = double]
Which are the types of the paramters i and j. So does the compiler just
use its type knowledge to create the "proper" instance of the function?
If so, since that is what it seems to be doing, is this part of the
official C++ standard?
Thanks,
Mike
------CODE------
#include <iostream>
using namespace std;
template<class N, class T>
N min_t(N first, T second)
{
if(first < second)
{
return first;
}
else
{
return second;
}
}
int main(int argc, char ** argv)
{
int i = 3;
double j = -1;
double k = min_t(i,j);
std::cout << k << std::endl;
return 0;
}
function or class when the user does not specify the template type?
GCC reports that the code below is using min_t with the form:
N min_t(N, T) [with N = int, T = double]
Which are the types of the paramters i and j. So does the compiler just
use its type knowledge to create the "proper" instance of the function?
If so, since that is what it seems to be doing, is this part of the
official C++ standard?
Thanks,
Mike
------CODE------
#include <iostream>
using namespace std;
template<class N, class T>
N min_t(N first, T second)
{
if(first < second)
{
return first;
}
else
{
return second;
}
}
int main(int argc, char ** argv)
{
int i = 3;
double j = -1;
double k = min_t(i,j);
std::cout << k << std::endl;
return 0;
}