I wrote little wrapper for XML Lite library to use it in my MFC project. Can I use this code?
CString GetValue()
{
const WCHAR* pwszValue = NULL;
UINT cwchValue = 0;
m_pReader->GetValue(&pwszValue, &cwchValue);
return CString(pwszValue);
}
Or shoud I use CString& parameter in GetValue method signature?
If you’re thinking about efficiency, then turn on optimization and measure. And consider whether the difference, if any, matters to you. It’s almost sure that the compiler will do return value optimization (RVO) here.
But as a general rule, use the coding practice that gives you more clear code, i.e. in this case the function result, which gives more concise, robust and readable calling code.
That said, it looks like you’re leaking memory for the
pwszValue, and the Hungarian notation prefix is not exactly readable and reduces clarity, so the code needs a bit of reworking even when you do the sensible thing and use the function result value.