Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "++*this" crashing

Reply
Thread Tools

"++*this" crashing

 
 
srinivas
Guest
Posts: n/a
 
      01-15-2007
i have gone through both the list iterator
m_iter_item & Iter_item from begin to end.
using _ptr->_Next and _ptr->_Prev
addresses in both the iterators are identical.

i have no clue why ++*this is crashing.

code in the above case is:
-----------------------------------------
1> class dummy
2> {
3> ..
4> ..
5> private:
6> list<mItem>::iterator m_iter_item;
7> }
8>
9> void dummy::func1()
10> {
11> list<mItem>::iterator iter_item;
12> getItem(&iter_item);
13> m_iter_item = iter_item;
14> ..
15> m_iter_item++;
16> ...
17> }
-----------------------------------------
when i changed the function func1() as

9> void dummy::func1()
10> {
11> list<mItem>::iterator iter_item;
12> getItem(&m_iter_item);
13> ..
14> m_iter_item++;
15> ...
16> }

there is no problem at all.

regards,
srinivas



Daniel T. wrote:
> "srinivas" <> wrote:
> >
> > is assignment of an iterator to another iterator valid?
> > i have found this assignment is creating problem.
> >
> > m_iter_item = iter_item;
> > m_iter_item++;

>
> Assignment from one object to another of the same type is valid if the
> class was written such that it is valid. The above code does not compile
> on its own (which does create a problem.
>
> You probably need to provide a valid op=.


 
Reply With Quote
 
 
 
 
srinivas
Guest
Posts: n/a
 
      01-15-2007
dear daniel,
"++*this" is in the C++ STL library, i did not write it.

srinivas

Daniel T. wrote:
> "srinivas" <> wrote:
>
> > i am incrementing a list iterator "m_item" in my .cpp file
> >
> > > m_item++

> >
> > m_item._ptr->_next is showing the valid item.
> >
> > but in the library overloaded function for ++
> >
> > 1 >_Myt_iter operator++(int)
> > 2 > { // postincrement
> > 3 > _Myt_iter _Tmp = *this;
> > 4 > ++*this;
> > 5 > return (_Tmp);
> > 6 > }
> >
> > (line 4)++*this is crashing...it is not showing any item in its next
> > pointer.
> >
> > what is the problem?

>
> Line 4 should be: ++(*this);


 
Reply With Quote
 
 
 
 
Clark S. Cox III
Guest
Posts: n/a
 
      01-15-2007
Daniel T. wrote:
> "srinivas" <> wrote:
>
>> i am incrementing a list iterator "m_item" in my .cpp file
>>
>>> m_item++

>> m_item._ptr->_next is showing the valid item.
>>
>> but in the library overloaded function for ++
>>
>> 1 >_Myt_iter operator++(int)
>> 2 > { // postincrement
>> 3 > _Myt_iter _Tmp = *this;
>> 4 > ++*this;
>> 5 > return (_Tmp);
>> 6 > }
>>
>> (line 4)++*this is crashing...it is not showing any item in its next
>> pointer.
>>
>> what is the problem?

>
> Line 4 should be: ++(*this);


Why?

(hint: there is no difference between ++(*this) and ++*this).

--
Clark S. Cox III

 
Reply With Quote
 
Ismo Salonen
Guest
Posts: n/a
 
      01-15-2007
srinivas wrote:
> i have gone through both the list iterator
> m_iter_item & Iter_item from begin to end.
> using _ptr->_Next and _ptr->_Prev
> addresses in both the iterators are identical.
>
> i have no clue why ++*this is crashing.
>
> --snip--


Perhaps you are removing items from the list (or adding to it ) ?
Is your iterator still valid ( the value in it pointed in list was
changed or even removed ? )

Or the iterator was already pointing to wrong location ( at or after
list.end() )

I suppose the iterator is normal forward iterator, not reverse_iterator.

Or you have memory corruption, you are overwriting the iterator fields
somehow.

ismo
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      01-15-2007
srinivas wrote:

> hi Ondra
> thanks for reply.


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox crashing - safe mode? Z Firefox 2 02-15-2005 08:37 PM
FireFox Crashing Joe Jance Firefox 2 06-19-2004 10:20 AM
Random links crashing Mozilla Leif K-Brooks Firefox 0 12-22-2003 06:13 PM
Mac 1.5RC2 download crashing issues sport0boy@netscape.net Firefox 4 10-14-2003 08:20 PM
SICK of Mizilla crashing Thomas Curmudgeon Firefox 4 09-29-2003 12:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57