Re: C++ question related to casting

From: Nick Lewycky <nicholas@dont-contact.us>
Date: Tue, 23 May 2006 13:22:23 -0400

Henrik Nordstrom wrote:
> Hi Robert,
>
> can you (or someone else who groks C++ casts) please explain why this
> happened?
>
> http://www.squid-cache.org/Versions/v3/3.0/changesets/10249.patch
>
>
> store.cc:712
>
> ((HttpHeader) pe->getReply()->header).putStr(HDR_VARY, vary.buf());

It's a temporary. pe->getReply()->head will get casted into the
HttpHeader, used to call putStr(...), then its life is over, at which
point the C++ implementation is free to destroy it at its leisure (some
impl's do it after the end of the statement, some wait until the end of
the function).

Even if you'd said "HttpHeader HH = ...", it would still create a
temporary, copy-construct the new HttpHeader, and then destroy the
temporary.

Nick Lewycky
Received on Tue May 23 2006 - 11:58:04 MDT

This archive was generated by hypermail pre-2.1.9 : Thu Jun 01 2006 - 12:00:04 MDT