我有C++代碼將GUID(無符號長整型)映射到結構。C++「沒有匹配函數調用」的錯誤結構
#include <string>
#include <map>
#include <iostream>
typedef unsigned long GUID;
enum Function {
ADDER = 1,
SUBTRACTOR = 2,
MULTIPLIER = 3,
SQUAREROOT = 4
};
struct PluginInfo
{
GUID guid;
std::string name;
Function function;
PluginInfo(GUID _guid, std::string _name, Function _function) {guid = _guid, name = _name, function = _function;}
};
typedef std::map<GUID, PluginInfo> PluginDB;
PluginInfo temp1(1, "Adder", ADDER);
PluginInfo temp2(2, "Multiplier", MULTIPLIER);
PluginDB::value_type pluginDbArray[] = {
PluginDB::value_type(1, temp1),
PluginDB::value_type(2, temp2)
};
const int numElems = sizeof pluginDbArray/sizeof pluginDbArray[0];
PluginDB pluginDB(pluginDbArray, pluginDbArray + numElems);
int main()
{
std::cout << pluginDB[1].name << std::endl;
}
當我編譯它時,我收到了錯誤信息。
/usr/include/c++/4.2.1/bits/stl_map.h: In member function ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = long unsigned int, _Tp = PluginInfo, _Compare = std::less, _Alloc = std::allocator >]’: mockup_api.cpp:58: instantiated from here /usr/include/c++/4.2.1/bits/stl_map.h:350: error: no matching function for call to ‘PluginInfo::PluginInfo()’ mockup_api.cpp:29: note: candidates are: PluginInfo::PluginInfo(GUID, std::string, Function) mockup_api.cpp:24: note:
PluginInfo::PluginInfo(const PluginInfo&)
什麼可能是錯誤的?
可能重複的[無法訪問std :: map中的結構值](http://stackoverflow.com/questions/36636610/cannot-access-struct-value-in-stdmap) – Yakk 2016-04-15 01:50:12