c++ - G++:不明确案例的默认重载

标签 c++ g++ overloading

给定两个函数,像这样

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) 这样的情况,重载显然是模棱两可的

有什么方法可以为这种情况指定默认重载吗?不必与 GNU C++ 编译器兼容,因为我已经在使用几个独特的约定。 理想情况下,像

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);

可以看到结果here

关于c++ - G++:不明确案例的默认重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354166/

相关文章:

C++ vector 数组运算符计算成本高?

c++ - CUDA:使用 G++ 链接器和 cuda 对象文件创建对象

c++11 - Clang 不允许 static_cast 到带有模板的父类,而 g++ 和 icc 允许

c++ - 了解 OOP 关联和函数 (c++)

c++ - char(*)[int] 在 C++ 中是什么意思?

c++ - 代理模式可以容纳模板函数吗?

c++ - 重载 << 运算符 : struct with vector of structs

java - 重载构造函数调用其他构造函数,但不是第一条语句

c++使用int和char *重载构造函数

c++ - 如何在使用 cmake 构建的 LLVM 中启用 --debug-only?