[Qt-interest] Strange (as for me) QByteArray behavior
Paul Miller
paul at fxtech.com
Wed Dec 8 17:22:38 CET 2010
On 12/8/2010 2:31 AM, Thiago Macieira wrote:
> On Wednesday, 8 de December de 2010 09:07:52 Konrad Rosenbaum wrote:
>> On Wednesday 08 December 2010, Ivan Kharin wrote:
>>>> QByteArray tmp = username.toAscii();
>>>
>>> const QByteArray&tmp = username.toAscii(); // avoid copy: const ref to
>>> function result == // keep automatic variable intact until end of
>>> scope
>>
>> I don't think this can work reliably. C++ is not a garbage collected
>> language, the reference becomes invalid immediately after the semicolon.
>
> That's not correct. The above is perfectly valid C++.
How does that work? Is the temporary QByteArray returned from toAscii()
somehow kept around on the stack once the reference to it is made?
More information about the Qt-interest-old
mailing list