template <typename T>
void f(paramTyep param);
f(expr);
template
void f(T& param);//T& 参数类型
int x = 0;
const int cx = x;
const int& rx = x; //rx是别名
f(x); //调用 f(int&)
f(cx);//调用f(const int&)
f(rx);//调用f(const int&)
void f(const T& param);//const T& 参数类型
f(x); //调用 f(const int&)
f(cx);//调用f(const int&)
f(rx);//调用f(const int&)
template
void f(T* param) // param 是一个指针
f(&x) //T是int ,param 类型是 int*
f(px);T是const int参数类型是 const int*
参数类型是万能引用
template
void f(T&& param) // param 是万能引用,既可以传递左值,又可以传递右值
int x = 1;
f(x);x 是一个值,T是Int&,类型是int&
f(1);1是右值,T是int,参数类型是int&&
参数类型既不是指针也不是引用
template
void f(T&& param);// 按值传递
int x = 1;
const int cx =x;
const int& rx = x;
f(x);// T 和参数类型都是Int
f(cx);// T 和参数类型都是Int
f(rx);// T 和参数类型都是Int
const char* const ptr = "hehws";
f(ptr);//T 是 const char*
参数是数组
const char name[] = "ddd";
const char * ptrName = name;
template
void f(T param);// 按值传递
f(name) // T是const char*
template
void f(T& param);//
f(name) // T是const char[4]编译器推导数组长度
参数是函数
template
void f1(T param);// 按值传递
template
void f2(T & param);// 按值传递
f1(someFunc);//参数是函数的指针, 类型是 void(*)()
f2(someFunc);//参数是函数的y引用, 类型是 void(&)()