Re: problem with link list by JSmith
JSmith
Wed Sep 29 15:07:33 CDT 2004
Correct me if I'm wrong. I was assuming that way I would access to a feild
of the structure.
as it is placed by below code so it should be accessbile thru the "p" again.
> > while(condition for reading a table)
> > {
> > p = new MyStruct;
> >
> > p->field0 = data1; //placing data into struct fields
> > p->field1 = data2;
> >
> > mylist.AddHead(p); //add the struct into link list
>
Any comment on this?
thanks,
JSmith
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eYYLF1lpEHA.592@TK2MSFTNGP11.phx.gbl...
> "JSmith" <jsmithmitra@yahoo.com> wrote in message
> news:%23W7AfxlpEHA.1272@TK2MSFTNGP09.phx.gbl
> > Hi Igor,
> >
> > Ok, this is the code I have, the previous one had some mistakes while
> > I was typig it sorry. Please let me know why the last phase which
> > reads back the data from link list only shows the last inserted node?
> >
> > typedef struct {
> > LONG field0;
> > CString field1;
> > CString field2;
> > CString field3;
> > CString field4;
> > }MyStruct;
> >
> > MyStruct* p = NULL;
> > CList <MyStruct, MyStruct> mylist;
> >
> > POSITION pos = MyList.GetHeadPosition();
> > while(condition for reading a table)
> > {
> > p = new MyStruct;
> >
> > p->field0 = data1; //placing data into struct fields
> > p->field1 = data2;
> >
> > mylist.AddHead(p); //add the struct into link list
>
> This code should not compile. CList <MyStruct, MyStruct>::AddHead takes
> MyStruct as a paramter, not MyStruct*.
>
> > POSITION pos = mylist.GetHeadPosition();
> > while(pos)
> > {
> >
> > mylist.GetNext(pos);
>
> This line affects on mylist and pos
>
> > AfxMessageBox(p->field0);
>
> This line uses p, which is not in any way related to mylist or pos. Why
> do you expect the first line to affect the second line?
> --
> With best wishes,
> Igor Tandetnik
>
> "On two occasions, I have been asked [by members of Parliament], 'Pray,
> Mr. Babbage, if you put into the machine wrong figures, will the right
> answers come out?' I am not able to rightly apprehend the kind of
> confusion of ideas that could provoke such a question." -- Charles
> Babbage
>
>