c++ - Returning a CString will call the destructor? -
what happenes if return cstring method? call destructor of cstring?
cstring f(){ cstring s = g(); return s; } const char* g(){ return new char[5]; }
thanks :)
not necessarily.
if compiler implements return value optimization (rvo) can set call f()
such s
constructed caller store return value, , therefore can elide calls cstring
copy constructor , destructor. optimization 1 of few exceptions permitted c++ standard as-if optimization rule.
if compiling optimizations disabled, see 1 or more calls cstring
copy constructor , destructor in processing call f()
.
Comments
Post a Comment