473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

"++*this" crashing

hi,
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?

thanks,
srinivas

Jan 15 '07 #1
14 1691

srinivas napsal:
hi,
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?

thanks,
srinivas
You should post here minimized compilable example which crashes.
Without it we can only guess.

Jan 15 '07 #2
hi Ondra
thanks for reply.

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++;
srinivas

Ondra Holub wrote:
srinivas napsal:
hi,
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?

thanks,
srinivas

You should post here minimized compilable example which crashes.
Without it we can only guess.
Jan 15 '07 #3

srinivas napsal:
hi Ondra
thanks for reply.

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++;
In general, it is valid. I think you have incorrect operator=. I do not
know internal structures of your iterator, so I am only guessing.
>
srinivas

Ondra Holub wrote:
srinivas napsal:
hi,
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?
>
thanks,
srinivas
You should post here minimized compilable example which crashes.
Without it we can only guess.
Jan 15 '07 #4
but the assignment operator= is not overloaded for list iterators.
so i am thinking assignment has gone wrong.

Ondra Holub wrote:
srinivas napsal:
hi Ondra
thanks for reply.

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++;

In general, it is valid. I think you have incorrect operator=. I do not
know internal structures of your iterator, so I am only guessing.

srinivas

Ondra Holub wrote:
srinivas napsal:
hi,
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?

thanks,
srinivas
>
You should post here minimized compilable example which crashes.
Without it we can only guess.
Jan 15 '07 #5

srinivas napsal:
but the assignment operator= is not overloaded for list iterators.
so i am thinking assignment has gone wrong.

Ondra Holub wrote:
srinivas napsal:
hi Ondra
thanks for reply.
>
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++;
In general, it is valid. I think you have incorrect operator=. I do not
know internal structures of your iterator, so I am only guessing.
>
srinivas
>
Ondra Holub wrote:
srinivas napsal:
hi,
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?
>
thanks,
srinivas

You should post here minimized compilable example which crashes.
Without it we can only guess.
Maybe you have to define your own implementation of assignment
operator. If you are allocating some memory with new and freeing it in
destructor, you definitely need define your own operator= and perform
deep copy.

I cannot say more, because I do not know anything about your
implementation :-(

Jan 15 '07 #6
"srinivas" <sk********@gmail.comwrote:
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);
Jan 15 '07 #7
In article <11*********************@38g2000cwa.googlegroups.c om>,
"srinivas" <sk********@gmail.comwrote:
hi,
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?
BTW, variables starting with underscore and a capital letter are
reserved. Don't use them unless you are writing a compiler.
Jan 15 '07 #8
"srinivas" <sk********@gmail.comwrote:
>
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=.
Jan 15 '07 #9

Daniel T. napsal:
"srinivas" <sk********@gmail.comwrote:
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);
++(*this) is the same as ++*this;

++ (preincrement) has the same priority as * (dereference).

Jan 15 '07 #10
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:
-----------------------------------------
1class dummy
2{
3..
4..
5private:
6list<mItem>::iterator m_iter_item;
7}
8>
9void 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

9void 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" <sk********@gmail.comwrote:

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=.
Jan 15 '07 #11
dear daniel,
"++*this" is in the C++ STL library, i did not write it.

srinivas

Daniel T. wrote:
"srinivas" <sk********@gmail.comwrote:
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);
Jan 15 '07 #12
Daniel T. wrote:
"srinivas" <sk********@gmail.comwrote:
>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
cl*******@gmail.com
Jan 15 '07 #13
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
Jan 15 '07 #14
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>
Jan 15 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Stevens | last post by:
Probably the wrong wording but since I'm not a scripter I won't claim to know what I'm talking about. I got this script from www.htmlgoodies.com <script language="JavaScript"> <!--...
3
by: Hodad | last post by:
I would like to adapt, as much as possible, the appearance and color red of the font in this button: <P><CENTER><BUTTON VALUE="SUBMIT"><A...
1
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC {...
3
by: maadhuu | last post by:
well,i am curious to know what would be the output of the following: delete this; basically , comment on this .
1
by: tnhoe | last post by:
Hi, <Form method='post' action="next.htm?btn="+"this.myform.myobj.value"> What is the correct syntax for above ? Regards Hoe
1
by: Shapper | last post by:
Hello, I am accessing a value in a XML value: news.Load(Server.MapPath("xml/ news.rss")) newslabel.Text = CType(news.SelectSingleNode("rss version=&quot;2.0 &quot;/channel/title").InnerText, String) ...
7
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
10
by: craig.keightley | last post by:
I am trying to get the next row within a loop for a script i am developing... I need to display a final table row within the table that i have displayed on the page, but i only want to show it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.