Boost logo

Boost Users :

From: Kevin Martin (kev82_at_[hidden])
Date: 2008-05-16 15:31:02


On 16 May 2008, at 18:43, Noah Roberts wrote:

> Kevin Martin wrote:
>>>
>> And to make matters worse, people might be tempted to do this!
>>
>> func1(func2().get());
>>

> Having fixed that, your call looks like this:
>
> func1(*func2());

My understanding of how this works was wrong. I thought the object
returned by func2 would go out of scope before the call to func1,
meaning the pointer/reference passed to func1 would be hanging. It
seems I am wrong though, at least with g++ and icc, so I guess I need
to go back to C++ 101.

func1() may be a member function of an object which needs to keep the
argument somewhere, that is why I prefer to pass a pointer. Passing a
reference gives the implication (at least to me) that the object is
not going to keep any link with the argument after the call returns.
Passing a pointer makes me think - hey, what is this object doing with
this thing?

Thanks,
Kevin Martin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net