【发布时间】:2012-01-25 08:31:56
【问题描述】:
我正在尝试实现三个函数并且有很多错误,所有这些错误都具有相同的签名:
error C2782: 'T0 ColorBurn(T0,T0)' : template parameter 'T0' is ambiguous
error C2782: 'T1 ColorDodge(T1,T1)' : template parameter 'T1' is ambiguous
我在哪里犯了错误?
这是我的代码:
template <class T0>
T0 ColorBurn(T0 base, T0 blend)
{
return (blend == 0.0) ? blend : std::max((1.0 - ((1.0 - base) / blend)), 0.0);
}
template <class T1>
T1 ColorDodge(T1 base, T1 blend)
{
return (blend == 1.0) ? blend : std::min(base / (1.0 - blend), 1.0);
}
template <class T>
T BlendVividLightf(T base, T blend)
{
return (blend < 0.5) ? ColorBurn(base, (2.0 * blend)) : ColorDodge(base, (2.0 * (blend - 0.5)));
}
调用 BlendVividLightf 的示例:
static pixel_t blend_vivid_light(pixel_t _p1, pixel_t _p2)
{
pixel_t po;
po.r = BlendVividLightf(_p1.r, _p2.r);
....
}
pixel_t - is my struct for rgb values:
typedef struct
{
float r;
float g;
float b;
} pixel_t;
【问题讨论】:
-
BlendVividLightf 中的 T 是什么类型。请显示此函数的调用。
-
_p1.r和_p2.r的类型是double吗?如果不是,则会导致编译错误。 -
_p1.r 和 _p2.r 是浮动的。为什么会导致问题?
标签: c++ templates compiler-errors type-mismatch