[Qt-interest] Qt code compiles fine on mscv9.0 but failed with gcc

Constantin Makshin cmakshin at gmail.com
Wed Jan 26 22:37:32 CET 2011


On Thursday 27 January 2011 00:08:44 Thiago Macieira wrote:
> On Wednesday, 26 de January de 2011 22:58:40 Constantin Makshin wrote:
> > I admit it's safer to forbid such usage to make code less error-prone, but
> > at the same time I think it's not as bad as you say. Correct me if I'm
> > wrong.
> 
> Like I said, it breaks the concept, which is why it's not allowed. You can 
> only bind a non-const reference to an object that exists and is persistent, 
> otherwise the reference might outlive the object being referenced, like my 
> example.
Storing pointers or references to external objects is a dangerous idea. Modifying objects passed as non-const references is confusing and modifying temporary objects passed as non-const references is useless. I completely agree with you that things shouldn't be done this way.

> Your example is actually very bad. What happens if you don't pass a temporary, 
> but a normal object? The contents are suddenly changed.
That was just an example, I never write such code. I always use pointers where the function may modify an object so people looking at something like "function(&foo)" won't be [very] surprised if "foo" gets changed even if they didn't read function description.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110127/1873721a/attachment.bin 


More information about the Qt-interest-old mailing list