【发布时间】:2017-03-15 12:44:00
【问题描述】:
#include <string>
template
<
typename CharType,
template<class, class, class> class StringType = std::basic_string
<CharType, std::char_traits<CharType>, std::allocator<CharType>>
>
void f(CharType, StringType)
{}
int main()
{
char c;
std::string str;
f(c, str);
//
// error : default template argument for
// a template template parameter must be a class template
//
}
为什么不能默认template template parameter?
【问题讨论】:
-
如果您阅读错误消息,它会说“模板模板参数必须是类模板”。
std::basic_string本身是一个类模板。std::basic_string <CharType, std::char_traits<CharType>, std::allocator<CharType>>不是模板,它是从std::basic_string模板派生的具体类。
标签: c++ c++11 templates overloading template-templates