Afficher un message
Vieux 18/10/2007, 14h59   #8
Yannick Tremblay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pimpl idiom without dynamic memory allocation

In article <47165e09$0$26728$426a74cc@news.free.fr>,
Michael DOUBEZ <michael.doubez@free.fr> wrote:
>Daniel Lidström a écrit :
>> In article <4716585e$0$25087$426a74cc@news.free.fr>,
>> Michael DOUBEZ <michael.doubez@free.fr> wrote:
>>
>>> Daniel Lidström a écrit :
>>>> // create the pimpl instance without using new
>>>> Line::Line(const std::string& s) : m_pimpl(LineImpl(s)) {}
>>> Your local is destroyed when going out of scope. Doesn't it ?

>>
>> No it isn't. It is actually ok to bind a temporary object to a const
>> reference. There will be no "dangling" reference.

>
>It is ok to bind it but that doesn't mean the lifetime of the temporary
>is extended.
>
>Example:
>const std::string& foo()
>{
> return std::string("bar");
>}
>
>The value returned by foo() is an dangling reference.
>


Euh, it's not what he is doing, it's more like:

std::string foo()
{
return std::string("bar");
}

int main()
{
std::string const & val = foo();
....


  Réponse avec citation
 
Page generated in 0,05226 seconds with 9 queries