【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 }

一元“++”:“_Iter”不定义该运算符或到预定义运算符可接收类型的转换

【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 }

 

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
猜你喜欢
  • 2021-06-06
  • 2021-06-27
  • 2021-11-13
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案