[Interest] Help, please !!!

Nikos Chantziaras realnc at gmail.com
Thu Apr 26 23:15:02 CEST 2012


On 26/04/12 23:51, Andre Somers wrote:
> Op 26-4-2012 18:47, Nikos Chantziaras schreef:
>> On 26/04/12 19:01, André Somers wrote:
>>> Op 23-4-2012 20:44, Nikos Chantziaras schreef:
>>>> Then you're not doing what you think you're doing:
>>>>
>>>>         QList<    QList<int>    >    listOfLists;
>>>>         QList<int>    listOfInts;
>>>>         listOfInts.append(10);
>>>>
>>>>         listOfLists.append(listOfInts);
>>>>         listOfLists[0][0] = 9;
>>>>
>>>>         qDebug()<<    listOfLists[0][0]<<    listOfInts[0];
>>>>
>>>> You are modifying a copy, so it prints"9 10"  instead of"10 10".  This:
>>>>
>>>>       listOfLists[0][0] = 9;
>>>>
>>>> modifies a copy of listOfInts.  Also the reverse is true.  If you modify
>>>> listOfInts, then the copy of it inside listOfLists is not updated.
>>>>
>>>> "Implicit sharing"  means that data is copied when it's modified.  It's
>>>> not a replacement for pointers.
>>>>
>>> Not true, in this case.
>> I posted code that proves my point.  It prints "9 10".  You can't argue
>> with that one ;-)
> The copy is made at the moment you _append_ the list, not at the moment
> you're modifying it. That's a big difference. So yes, your code prints
> "9 10", and it should! However, the issue was about if you could modify
> what's in that nested list. You said:
>   >  Note that with QList<  QList<int>  >  you can't modify the other lists.
> You'd only be modifying the copies.

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.




More information about the Interest mailing list