C++ 一不小心被delete两次
[来源] 达内 [编辑] 达内 [时间]2012-09-11
C++类中,有时候使用到传值调用(对象实体做参数),遇到这种情况,可要小心了!特别是当你所传值的对象生命周期较长,而非临时对象(生命周期段)的时候
C++类中,有时候使用到传值调用(对象实体做参数),遇到这种情况,可要小心了!特别是当你所传值的对象生命周期较长,而非临时对象(生命周期段)的时候。来看看下面的情况:
< div style="margin: 0px; padding: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> < div style="margin: 1em 0px !important; padding: 1px !important; width: 919px; position: relative !important; overflow-x: auto !important; overflow-y: hidden !important; font-size: 15px !important; background-color: white !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; line-height: 1.5 !important; " class="syntaxhighlighter cpp" id="highlighter_253164"> < div style="margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-color: rgb(108, 226, 108) !important; border: none !important ; bottom: auto !important; float: none !important; height: 11px !important; left: auto !important; line-height: 1.5 !important; outline: 0px !important; overflow: visible !important; position: absolute !important; right: 1px !important; text-align: left !important; top: 1px !important; vertical-alig n: baseline !important; width: 11px !important; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: normal !important; font-style: normal !important; font-size: 10px !important; min-height: inherit !important; z-index: 10 !important; color: white !important; background-position: initial initial !important; background-repeat: initial initial !important; " class="toolbar"> ?1
#include <iostream>