سؤال

m_sUser.compareNoCase(pmA2U("pmkerberosuser").buffer())

pmA2U returns an object by value which has a member function buffer() for accessing its internal buffer. Will the temporary object constructed for the return value of pmA2U survive till the enclosing functioin compareNoCase is completed, to which it is passed as a parameter?

هل كانت مفيدة؟

المحلول

Yes. A temporary lasts until the end of the full expression that creates it. In this case, the full expression is the entire statement, so it will last until after the function returns.

Make sure the function doesn't store a pointer or reference to the buffer anywhere, since that would be invalidated shortly after it returns.

نصائح أخرى

The temporary object constructed for the return value of pmA2U() will survive until the enclosing functioin compareNoCase() is completed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top