[英]Function overloading in C++ with int and int64_t. Ambiguous match with "1LL"
#include <iostream>
void hi(int x) {
std::cout << "hi\n";
}
void hi(int64_t y) {
std::cout << "hi2\n";
}
int main() {
hi(3LL);
}
Why does it throw ambiguous match?为什么它会抛出模棱两可的比赛? I think it should resolves to the second function since it's an exact match.
我认为它应该解析为第二个 function,因为它是完全匹配的。 Or is int64_t a different type from 3LL?
还是 int64_t 是与 3LL 不同的类型?
It seems that the error only occurs on some compiler, namely g++ but not clang. Not sure if it is caused by different compiler flags or version used though.似乎错误只发生在某些编译器上,即 g++ 而不是 clang。不确定它是否是由不同的编译器标志或使用的版本引起的。
Or is int64_t a different type from 3LL?
还是 int64_t 是与 3LL 不同的类型?
Yes, int64_t
is long
(in this implementation).是的,
int64_t
很long
(在此实现中)。 3LL
is long long
. 3LL
很long long
。
Modern IDE have a "go to definition" feature, where you can position your cursor over int64_t
and go to https://github.com/lattera/glibc/blob/master/bits/stdint-intn.h#L27 and then go to https://github.com/lattera/glibc/blob/master/posix/bits/types.h#L43 .现代 IDE 具有“转到定义”功能,您可以在其中将 position 您的 cursor over
int64_t
和 go 转换为https://github.com/lattera/glibc/blob/master/bits/stdint-2837.h然后 4到https://github.com/lattera/glibc/blob/master/posix/bits/types.h#L43 。
You can use:您可以使用:
int64_t(3);
instead of:代替:
3LL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.