错误的源码:
_alphas[t] = max(0,min(0.5f*log((1-minerr)/(minerr+0.00001f)),10));
错误提示:
error C2780: “const _Ty &std::min(const _Ty &,const _Ty &,_Pr)”: 应输入 3 个参数,却提供了 2 个
error C2782: “const _Ty &std::min(const _Ty &,const _Ty &)”: 模板 参数“_Ty”不明确
今天发现如上的错误,开始以为是函数调用的时候,自定义的函数与库函数名称重复所导致,但是究其原因,终究不是,在一个博友的日志中看到,说这样的错误是因为max/min函数中两个参数的参数类型不同造成的,简短而明了,于是尝试一下,由于:_alphas[t] 是float类型,于是改为:
_alphas[t] = (std::max<float>)(0,(std::min<float>)(0.5f*log((1-minerr)/(minerr+0.00001f)),10));
编译通过!撒花!!!
但是,仔细想来,却觉得这个函数那么奇怪,如果如果真的是类型问题,那么int与float的类型也是不一样的啊,但是改为
_alphas[t] = (std::max<float>)(0,(std::min)(0.5f*log((1-minerr)/(minerr+0.00001f)),10));
便又会出现上述的错误,终究不知是为什么。
如果改为
_alphas[t] = (std::max<float>)(0,(std::min<int>)(0.5f*log((1-minerr)/(minerr+0.00001f)),10));
却也可以通过编译