template <typename T>
void foo(T t)
{
... // do stuff with type T
}
template <typename T>
class class_template
{
// class body
};
template<> // failed attempt at full specialization
void foo(class_template<T> t) // which doesn't work of course
{
//full specialization for all classes of class_template
}
在上面的代碼中,我該如何顯式地將函數foo與類模板進行專門化?如何使用類模板完全專用函數模板?
這裏的矛盾是,如果它是「對所有class_template類」,那麼它不是「完全專業化」。根據定義,完全專業化僅適用於每個模板參數的* 1個可能的值。 –
你的嘗試有'template <>'但是然後使用未聲明的模板參數'T',它不能工作,什麼是'T'?正如前面的評論所說,你使用了錯誤的術語,你想要做的是**部分**專門化功能模板,這是不允許的。 –