Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用c+;中的列表指针值分配标准映射+;_C++_List_Pointers_Dictionary_Std - Fatal编程技术网

C++ 用c+;中的列表指针值分配标准映射+;

C++ 用c+;中的列表指针值分配标准映射+;,c++,list,pointers,dictionary,std,C++,List,Pointers,Dictionary,Std,我试图为我的std映射的每个键分配一个列表,但是使用新的操作符我得到了一些错误(没有预定义的构造函数是find和其他),为什么 我的代码如下: std::map<QString, *std::list<ExecutionGUIObject*>> execEvtMap; execEvtMap["t1"] = new std::list<ExecutionGUIObject*>; std::map execEvtMap; execEvtMap[“t1”]=新的

我试图为我的std映射的每个键分配一个列表,但是使用新的操作符我得到了一些错误(没有预定义的构造函数是find和其他),为什么

我的代码如下:

std::map<QString, *std::list<ExecutionGUIObject*>> execEvtMap;

execEvtMap["t1"] = new std::list<ExecutionGUIObject*>;
std::map execEvtMap;
execEvtMap[“t1”]=新的标准::列表;
这意味着“指向ExecutionGUIObject对象指针列表的指针”

这意味着“指向ExecutionGUIObject对象指针列表的指针”。

如所述,这是映射声明中的一个小语法错误。但是通过动态分配
std::list
,您将一无所获,那么为什么要自找麻烦呢?只需使用列表地图

std::map<QString, std::list<ExecutionGUIObject*>> execEvtMap;

// Creates a new (empty) list for key "t1" if one does not already exist.
void(execEvtMap["t1"]);

// Creates a new list for key "t1", or clears the existing one.
execEvtMap["t1"].clear();

// Erases a key and its list
execEvtMap.erase("t1");
如所述,这是映射声明中的一个小语法错误。但是通过动态分配
std::list
,您将一无所获,那么为什么要自找麻烦呢?只需使用列表地图

std::map<QString, std::list<ExecutionGUIObject*>> execEvtMap;

// Creates a new (empty) list for key "t1" if one does not already exist.
void(execEvtMap["t1"]);

// Creates a new list for key "t1", or clears the existing one.
execEvtMap["t1"].clear();

// Erases a key and its list
execEvtMap.erase("t1");

请包含错误的确切文本。请包含错误的确切文本。如果我必须从类(如get方法)公开列表,那么这两个方法的效率是相同的@Quentin@Daniel例如
std::list&getList(QString键)?是的,同样的费用。事实上,您只能通过减少动态分配来加快速度。另外,没有可管理的原始指针。如果我必须从类(比如get方法)公开列表,那么这两个方法的效率是相同的@Quentin@Daniel例如
std::list&getList(QString键)?是的,同样的费用。事实上,您只能通过减少动态分配来加快速度。另外,没有野生的原始指针需要管理。
std::map<QString, std::list<ExecutionGUIObject*>> execEvtMap;

// Creates a new (empty) list for key "t1" if one does not already exist.
void(execEvtMap["t1"]);

// Creates a new list for key "t1", or clears the existing one.
execEvtMap["t1"].clear();

// Erases a key and its list
execEvtMap.erase("t1");
std::map<QString, std::list<std::unique_ptr<ExecutionGUIObject>>> execEvtMap;