一元“++”:“_Iter”不定義該運算符或到預定義運算符可接收類型的轉換


【1】復現編譯錯誤

C2675: 一元“++”:“_Iter”不定義該運算符或到預定義運算符可接收類型的轉換

 1 #include <map>
 2 #include <unordered_map>
 3 
 4 struct GJGActionEvent  5 {  6     std::map<std::string, std::string> input;  7     std::unordered_map<std::string, std::string> output;  8 };  9 
10 int main() 11 { 12     std::string key = "input"; 13     std::string value = "100"; 14  GJGActionEvent actEvt; 15     actEvt.input.insert(key, value);     // error:C2675
16     actEvt.output.insert(key, value);    // eroor:C2675
17 
18     return 0; 19 }

【2】解決方法

代碼如下:

 1 #include <map>
 2 #include <unordered_map>
 3 
 4 struct GJGActionEvent
 5 {
 6     std::map<std::string, std::string> input;
 7     std::unordered_map<std::string, std::string> output;
 8 };
 9 
10 int main()
11 {
12     std::string key = "input";
13     std::string value = "100";
14     GJGActionEvent actEvt;
15 //  actEvt.input.insert(key, value);     // error:C2675
16 //  actEvt.output.insert(key, value);    // eroor:C2675
17 
18     actEvt.input.insert(std::make_pair(key, value));   // OK
19     actEvt.output.insert(std::make_pair(key, value));  // OK
20 
21     return 0;
22 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM