簡體   English   中英

Function 在 C++ 中用 int 和 int64_t 重載。 與“1LL”的不明確匹配

[英]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);
}

為什么它會拋出模棱兩可的比賽? 我認為它應該解析為第二個 function,因為它是完全匹配的。 還是 int64_t 是與 3LL 不同的類型?

似乎錯誤只發生在某些編譯器上,即 g++ 而不是 clang。不確定它是否是由不同的編譯器標志或使用的版本引起的。

還是 int64_t 是與 3LL 不同的類型?

是的, int64_tlong (在此實現中)。 3LLlong long

現代 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

您可以使用:

int64_t(3);

代替:

3LL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM