G++:模糊情况下的默认重载

G++: Default Overload For Ambiguous Case

本文关键字:默认 重载 情况下 模糊 G++      更新时间:2023-10-16

给定两个函数,比如

inline V2T<Int16> GS(float x, float y, int xOff, int yOff, Uint8 f = 0x00);
inline V2T<Int16> GS(float x, float y, int xOff, int yOff, int maxW = -1, int maxH = -1, Uint8 f = 0x00);

对于GS(float,float,int,int)这样的情况,重载显然是不明确的

有什么方法可以为这样的情况指定默认重载吗?不必与GNUC++编译器兼容,因为我已经使用了几个独特的约定。理想情况下,类似的东西

inline V2T<Int16> GS(... , Uint8 f = 0x00) __default;
inline V2T<Int16> GS(... , int maxW = -1, int maxH = -1, Uint8 f = 0x00);

导致编译器自动解析为支持第一个(__default)函数。

我看到的所有问题都是针对第一次遇到这个错误的新手,所以这可能已经得到了回答,但被掩盖了。提前感谢!

尝试这个

inline V2T<Int16> GS(float x, float y, int xOff, int yOff, Uint8 f = 0x00);
// this one is not default one
template <class = void>
inline V2T<Int16> GS(float x, float y, int xOff, int yOff, int maxW = -1, int maxH = -1, Uint8 f = 0x00);

您可以在这里看到结果

最明显的修复是

inline V2T<Int16> GS(float x, float y, int xOff, int yOff, Uint8 f = 0x00);
inline V2T<Int16> GS(float x, float y, int xOff, int yOff, int maxW, int maxH = -1, Uint8 f = 0x00);

因为您的意图是CCD_ 1实际上不能被赋予默认值。