Afficher un message
Vieux 17/10/2007, 20h09   #4
Michael DOUBEZ
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pimpl idiom without dynamic memory allocation

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.

Michael

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