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

 

posted @ 2020-04-03 00:10  kaizenly  阅读(2638)  评论(0编辑  收藏  举报
打赏