为什么这个为三种整数类型重载的函数无法编译?

Why does this function overloaded for three integer types fail to compile?

本文关键字:重载 类型 函数 编译 整数 三种 为什么      更新时间:2023-10-16

定义一个重载三种大小整数的函数失败了。为什么?

byte hack(byte x)
{
   return x+1;
}
unsigned short hack(unsigned short x)
{
   return x+2;
}
unsigned int hack(unsigned int x)
{
   return x+3;
}

编译器告诉我:zz.cpp:98:错误:重新定义' unsigned int hack(unsigned int) '

你的编译器/代码认为byteunsigned int是一样的…

重载函数的不同之处在于它们的形参计数和/或类型,而不是返回类型。这是三个不同的函数