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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -