我創建了一個非常簡單的示例來說明問題:
#include <unordered_map>
int main() {
struct Example {
int num;
float decimal;
};
std::unordered_map<int, Example> map;
map.insert(1, { 2, 3.4 }); // Error none of the overloads match!
}
我應該能夠插入到 int 和 struct Example 的映射中,但是編譯器說沒有一個多載匹配..?
uj5u.com熱心網友回復:
錯誤訊息的原因是,沒有一個多載std::unordered_map::insert采用鍵和值引數。
你應該做
map.insert({1, { 2, 3.4 }});
代替
map.insert(1, { 2, 3.4 });
您可以在https://en.cppreference.com/w/cpp/container/unordered_map/insert參考 std::unordered_map::insert 的第 6 次多載
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/504947.html
下一篇:顯示外部行程除錯輸出
