[Interest] Help, please !!!
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Fri Apr 27 00:09:06 CEST 2012
On 27/04/12 00:45, Scott Aron Bloom wrote:
> Nope. That was not the issue. The issue was that when you append
> list A into list B, you can't get to list A because what's inside list
> B is a copy of A, not A itself. You might want to read again from the
> first post.
>
> _______________________________________________
>
> Nope.. not at all..
>
> The problem is with your testcase Nikos... NOT implicit sharing..
>
> listOfInts.append(10);
>
> Expliticly PREVENTS the modification of the listOfInts variable.
>
> It takes in a const object reference, Guarenteeing the original will
> NOT be modified.. And implying that any modification to the original
> will not effect the copy as well..
I said:
list->append(&someOtherList);
You said:
If someOtherList goes out of scope, you will be pointing to
a deleted list.
Since QList uses implicit sharing, the cost of removing the
inner pointer isn't that much.
QList< QList< int > >
Is much safer.
I said:
Note that with QList< QList<int> > you can't modify the other
lists. You'd only be modifying the copies.
You said:
Not true at all..
I don't see what it is that we're discussing here. Your statement was
simply wrong. My suggestion to be able to modify the other list:
list->append(&someOtherList);
Your suggestion to be able to modify the other list:
list->append(someOtherList);
which doesn't work. You will *not* be able to modify 'someOtherList'
through 'list'. It's basic C++. You *need* to hold a pointer, or else
you're dealing with a copy. Whether that copy uses implicit sharing
doesn't matter at all; implicit sharing is just an optimization.
_______________________________________________
Wrong...
If the container list, allowed for non-const parameters passing (like it
could in Qt 3.0) You COULD "copy" the original and modify it.
In fact, it was a bug I had to work through with the help of trolltech
support 8 or 9 years back in the old graphics view.
Now by making it a constant, its much safer...
But keeping a pointer to something on the stack, that could go out of
scope, is VERY VERY dangerous...
Scott
More information about the Interest
mailing list