[C++]模板编译模式

函数模板的定义可以用来作为一个无限个函数实例集合定义的规范描述(prescription)。模板本身不能定义任何函数。例如,当编译器实现看到下面的模板定义时

template <typename Type>
    Type min(Type t1,Type t2)
{
    return t1<t2?t1:t2;
}

这时候你可能以为自己写好了一个函数,但是编译器不会认为这是一个函数,它只会保存这个形式,直到min()这个函数被使用:

int i,j;
double dsth = min(i,j);

这时候才会根据

posted @ 2021-01-23 01:09  zengzhaocheng  阅读(55)  评论(0编辑  收藏  举报