編譯器比較函式模板的形參(template parameter)與對應的調用實參(argument used in the function call)的類型,以確定模板參數的類型。形參的類型必須是下述特定情形之一:
T const T volatile T T& T* T[10] A<T> C(*)(T) T(*)() T(*)(U) T C::* C T::* T U::* T (C::*)() C (T::*)() D (C::*)(T) C (T::*)(U) T (C::*)(U) T (U::*)() T (U::*)(V) E[10][i] B<nowiki><i></nowiki> TT<T> TT<nowiki><i></nowiki> TT<C>
說明:
T, U, V表示模板類型參數
10表示任意整數常量
i表示模板非類型參數
[i]表示數組界( represents an array bound of a reference or pointer type, or a non-major array bound of a normal array)
const int i=102; const int &j=i; template<class T> void foo(T& arg) { arg=101;}// 函式模板 foo(j); // 編譯錯誤: 'arg': you cannot assign to a variable that is const