Re: faq: use position of CList can find the element?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Tue, 03 Apr 2007 17:07:15 +0800, fcvcnet <fcvcnet@xxxxxxx> wrote:

void fun(POSITION pos)
{
CList <CPoint, CPoint&> copy;
copy.RemoveAll();
//CPoint hh=copylist.GetAt(POSITION(0x004215e4));
POSITION pos1(POSITION(0x004215e4));
CPoint dd=copy.GetNext(pos1); <--- interest thing is here
CPoint jj=copy.GetNext(pos); <--- and here.
//<--- the copy is empty but it still can take correct value of dd and
jj back. It seemed work like pointer.

You are kind of violating the "contract" of CList.

Joe already answered you in very clear form in a previous post:
(Maybe you missed it because the thread subject was changed from your
original subject - with the unusual "faq" - to this:
"Re: use position of CList can find the element?")

<cite author="Joe">
You have to be very careful. The POSITION values are valid only as
long as the elements
still exist, so if there is a deletion or insertion that happens
between the time you
compute these values, they will no longer represet what you think they
do.
</cite>

You did a CList.RemoveAll, so the POSITION values are just "junk".
(Moreover, in your code, you are doing a RemoveAll on a CList
constructed with a default constructor, so the CList is already
empty... I can't understand your code.)

MrAsm
.



Relevant Pages

  • Re: Simple inheritence question
    ... by eliminating 'bool b' from the constructor in the second example and letting the constructor set the value of is_blank based upon the value of letter. ... Note that with DbC, we can put a contract on the constructor that keeps the input to the constructor within the bounds, or a space. ... The problem with the DbC approach is that one has to make an evaluation of whether there will be an inconsistency in the data _in every access context_ whenever there is a change to the way the data is modified. ... If one eliminates the dependency via normalization that complication is /never/ an issue so it doesn't even need to be considered during DbC analysis. ...
    (comp.object)
  • Re: McLaren verdict
    ... don't have constructor points to worry about any more. ... contract" idea - as there's no constructors' points up for grabs, ... so there might be a certain amount of ... Whilst Alonso has looked bad in all this and my opinion of the guy is ...
    (rec.autos.sport.f1.moderated)
  • Re: Why dosnt this work?
    ... On Tue, 30 Mar 2004, Joe wrote: ... > Yes it does, that is my constructor. ... Please read the posting guidelines for this group, ... say that you should post a small *but complete* program demonstrating the ...
    (comp.lang.perl.misc)
  • Re: McLaren verdict
    ... In article, Jay Blanc ... don't have constructor points to worry about any more. ... contract" idea - as there's no constructors' points up for grabs, ...
    (rec.autos.sport.f1.moderated)
  • Re: COpy object
    ... Joe, ... TDaily* Copy; // Copy constructor ... an assignment operator should return a reference: ... involve TDaily's and TDaily references, ...
    (comp.lang.cpp)