假设我有一些unordered_map指向类实例的指针,从该映射中删除一个对象也会删除该实例?
(重写问题:)如果我想删除该实例,哪个版本是正确的?
if(it != map.end())
{
delete it->second;
map.erase(it);
}
Run Code Online (Sandbox Code Playgroud)
或者干脆
if(it != map.end())
map.erase(it);
Run Code Online (Sandbox Code Playgroud)
?
更新:正如许多人所建议的那样,我开始使用shared_ptr它,效果很好!
我正在尝试使用跳转表在程序集(MASM64,Windows,x64)中实现算法。基本思想是:我需要对数据进行3种不同类型的操作。这些操作取决于一些变量,但是我发现实现许多切换和许多长的实现很乏味。
PUBLIC superFunc@@40 ;__vectorcall decoration
.DATA
ALIGN 16
jumpTable1 qword func_11, func_12, func_13, func_14
jumpTable2 qword func_21, func_22, func_23, func_24
jumpTable3 qword func_31, func_32, func_33, func_34
.CODE
superFunc@@40 PROC
;no stack actions, as we should do our stuff as a leaf function
;assume the first parameter (rcx) is our jumpTable index, and it's
;the same index for all functions
mov rax, qword ptr [rcx*8 + offset jumpTable1]
mov r10, qword ptr [rcx*8 + offset jumpTable2]
mov r11, qword ptr [rcx*8 …Run Code Online (Sandbox Code Playgroud)