>>> >>> Change & change_running = Change() ; >> >> change_running points to nothing valid. > > Hm... not really. > > The problem is that Change() is an rvalue that can't be bound > to an non-const reference (says the Standard, not MSVC...) > > If it were written > > Change const & change_running = Change(); > > it would be valid, and the lifetime of the temporary Change() > would be extended to the one of the reference it is bound to > (i.e. change_running, which lives to the end of the block). > > However, I doubt such a thing is very useful in any case. You get a non-mutable default-constructed object...
OK.. Time to get bjarne into bed ;-) >> >>> Change const & change = par_.lookupChange(pos); .... >>> change_running = change; >>> >>> to copy the members of the object. Is this ok ? > >Why not > > Change change_running = change; > >? > Well, if it was so simple. To give a more elusive example: Change change_running = Change(); for( .. ) { Change change = par_.lookupChange(pos); if (!change.isSimilarTo(change_running)) { doSomething; change_running = change; } } if (change_running.isRunning) .... It is concise and it works, but always ? Vincent