G++:模糊情况下的默认重载
G++: Default Overload For Ambiguous Case
给定两个函数,比如
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实际上不能被赋予默认值。
相关文章:
- 从类重载的新运算符运行非默认构造函数
- C++头/实现文件中的默认和重载构造函数?
- 模板中默认类型的重载运算符
- 重载运算符是具有较小默认对齐方式的新增运算符
- 类X有多个默认构造函数和对重载函数的模糊调用
- 重载方法的类接受模板和基类 - 如何默认某个方法
- 将重载函数分配给功能指针作为默认值
- C++ 重载 ostream 不适用于带有空参数的默认构造
- 重载基类中的方法,默认为成员变量
- 是否在重载选择期间未考虑默认参数的转换
- 在解析分配给默认参数值的重载函数时,要考虑哪组函数
- C++选择'wrong'默认参数的重载方法
- 继承并重载默认构造函数
- 如果我们在c++中重载构造函数,那么默认构造函数是否仍然存在
- C++使用默认参数重载
- C++:函数重载vs变分函数vs变分模板vs默认参数
- 构造函数重载和默认参数
- 在C++中使用默认参数时,重载函数的多个实例
- Qt C++新的类似方法.我是重载方法、编写新方法还是使用默认参数
- G++:模糊情况下的默认重载