[Interest] Help, please !!!
1+1=2
dbzhang800 at gmail.com
Fri Apr 27 02:08:46 CEST 2012
Hi Nikos & Scott,
IMO, both of you are right, but you are discussing two different things.
Debao
On Thu, Apr 26, 2012 at 4:13 PM, Nikos Chantziaras <realnc at gmail.com> wrote:
> On 27/04/12 01:48, Scott Aron Bloom wrote:
>> I'm not sure if you're serious or are trolling me for fun. I *do* have
>> a sense of humor, but this one I don't get :-/
>>
>> How is this "wrong?" You claim that if you do:
>>
>> QList<int> someOtherList;
>> QList< QList<int> > list;
>> list.append(someOtherList);
>>
>> you are able to modify 'someOtherList' through 'list'. You just can't.
>> Not the list, and also not its contents (since they're 'int', not
>> 'int*'). If you really are serious about what you're saying, even after
>> this discussion, then I have to give up.
>> ----------------
>> It has NOTHING TO DO WITH THE int vs int*,
>
> I only mentioned it in passing.
>
>
>> It has EVERYTHING to do with
>> you are sending in a const copy of the someOtherList...
>
> Actually that's also wrong. You are not sending a const copy. You are
> sending a const reference. But it doesn't matter. That's just an
> implementation detail done for optimization reasons. You cannot modify
> it and it has to be treated as a copy.
>
>
>>> 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.
>>
>> Isn't that the point? That you CANNOT modify it through the copy,
>> therefore if you do need to modify it you need a pointer rather than a
>> copy? But at the same time you claim the opposite.
>>
>> Or this is some kind of miscommunication.
>> --------------------------
>>
>> I claim, that with implicit sharing YOU CAN MODIFY the original list...
>> however, not via the constant.. Try using the operator[] instead.
>
> I already did and demonstrated that the original does not get modified:
>
> listOfInts.append(10);
> listOfLists.append(listOfInts);
> listOfLists[0][0] = 9;
> qDebug() << listOfLists[0][0] << listOfInts[0];
>
> Using listOfLists[0][0] to modify listOfInts does NOT work. Why don't
> you try the above yourself?
>
>
>>> But keeping a pointer to something on the stack, that could go out of
>>> scope, is VERY VERY dangerous...
>>
>> No one claimed otherwise.
>> ----------------
>>
>> You did when you suggested you use
>>
>> push(&otherList )
>
> I did not "suggest" this. This was listed, inside a comment, as an
> example. No one can suggest anything, because the OP did not state what
> it is he wanted to put in the list. So I wrote:
>
> list->append(new QList<int>);
> // Or:
> // list->append(&someOtherList);
>
> I am not teaching basic C++ whenever I post a solution to a problem :-/
> I assume that everybody knows that variables not created on the heap
> get destroyed when they go out of scope.
>
>
>> You are coming to the correct conclusing, but not for the correct
>> reason.. Using append/pushback etc, the list is copied using a const
>> reference to the data..
>
> Again, it is not copied, a const reference is held. But it doesn't matter.
>
>
>> Implicit sharing or not, will not allow modifications on either the copy
>> or the original to propagate to the other
>
> Then what exactly is the issue here? You end up agreeing with me, but
> there seems to be still some kind of issue?
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list