Chinaunix
标题:
为什么无法推导模版参数
[打印本页]
作者:
math_cai
时间:
2013-10-02 18:25
标题:
为什么无法推导模版参数
template<class char_type,class size_type>
struct hash_LNPS_default
{
size_type operator()(char_type value)const{
return value-char_type('a');
}
};
template<typename char_type,typename size_type,typename hash_type >
size_type LongestNPS(char_type *str_base,size_type size,hash_type hash=hash_LNPS_default<char_type,size_type>() )
{
...
}
size_t max=LongestNPS(str,strlen(str);
复制代码
error C2783: 'size_type LongestNPS(char_type *,size_type,hash_type)' : could not deduce template argument for 'hash_type'
作者:
linux_c_py_php
时间:
2013-10-02 22:46
楼主的做法没找到标准。
可以换一种做法如下,但是我查了一下发现C++11才支持函数模板默认参数, C++98只为类支持了这个特性:
template<typename char_type,typename size_type,typename hash_type = hash_LNPS_default<char_type,size_type> >
size_type LongestNPS(char_type *str_base,size_type size,hash_type hash=hash_type() )
{
}
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2