c++ “no matching function for call to” error with structure

前端 未结 2 546
一整个雨季
一整个雨季 2020-12-21 13:07

I have C++ code that maps GUID(unsigned long) to structure.

#include 
#include 
#include 

typedef unsigned long GU         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 13:20

    The problem is that when you say:

     pluginDB[1]
    

    you try to create an entry in the map (because [1] does not exist) and to do that as Jason points out, you need a default constructor. However, this is NOT a general requirement of standard library containers, only of std::map, and only of operator[] for std::map (and multimap etc.), which is a good reason why IMHO operator[] for maps et al should be done away with - it is far too confusing for new C++ programmers, and useless for experienced ones.

提交回复
热议问题