这两个声明有什么区别?
template<typename T, typename U>
template<typename T> template<typename U>
在这个问题的接受答案中对此进行了模糊的解释:专门化成员函数时出现“太多模板参数列表”错误 https://stackoverflow.com/questions/3595859/too-many-template-parameter-lists-error-when-specializing-a-member-function
我知道它们不是同一件事,但我很难找到教授后者用法的资源。解释和例子将不胜感激。
考虑一个需要两种类型的函数模板。这需要两个参数:
template<typename T, typename U>
bool isEqual(const T &t, const U &u) {
return t == u;
}
现在考虑一个带有成员函数模板的类模板。这需要两个列表:
template<typename T>
struct Foo {
template<typename U>
void bar(const U &u);
};
template<typename T>
template<typename U>
void Foo<T>::bar(const U &u) {/*do something with u*/}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)