一元“++”:“_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