By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Strange Results with Overloaded Operators

P: n/a
I'm having problems with the code you can find at http://planetevans.com/c

Particulary with test6(). However even with the earlier tests they work
fine when run, but crash when run in the debugger. I'm also still having
problems with the destructor.
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:69******************************@free.teranew s.com...
I'm having problems with the code you can find at http://planetevans.com/c

Particulary with test6(). However even with the earlier tests they work
fine when run, but crash when run in the debugger. I'm also still having
problems with the destructor.


Both your operator[] are wrong. Think carefully about what happens when
arrayLow is not zero.

Should have spotted this in your earlier post, sorry.

john
Jul 19 '05 #2

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...
Both your operator[] are wrong. Think carefully about what happens when
arrayLow is not zero.

Should have spotted this in your earlier post, sorry.

john


Okay that was a stupid mistake. Changed them to execute return
array[forLocation];

I'm still having problems though. With the destructor enabled it crashes on
test2(). Without it enabled it crashes on test3().
Jul 19 '05 #3

P: n/a
"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:51******************************@free.teranew s.com...
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...
Both your operator[] are wrong. Think carefully about what happens when
arrayLow is not zero.

Should have spotted this in your earlier post, sorry.

john


Okay that was a stupid mistake. Changed them to execute return
array[forLocation];

I'm still having problems though. With the destructor enabled it crashes on
test2(). Without it enabled it crashes on test3().


Still wrong.
What if a[-3] for IntArray a(-3, 6)?

--
ES Kim

Jul 19 '05 #4

P: n/a
Then it returns array[-3] which is a valid variable isn't it?
"ES Kim" <es***@svd.co.kr> wrote in message
news:bg**********@news1.kornet.net...
"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:51******************************@free.teranew s.com...
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...
Both your operator[] are wrong. Think carefully about what happens when arrayLow is not zero.

Should have spotted this in your earlier post, sorry.

john


Okay that was a stupid mistake. Changed them to execute return
array[forLocation];

I'm still having problems though. With the destructor enabled it crashes on test2(). Without it enabled it crashes on test3().


Still wrong.
What if a[-3] for IntArray a(-3, 6)?

--
ES Kim

Jul 19 '05 #5

P: n/a
"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:40******************************@free.teranew s.com...
Then it returns array[-3] which is a valid variable isn't it?


No. Array index starts from 0. You just changed the interface
using the array. It should be

int& IntArray::operator[] (int forLocation)
{
return array[forLocation - arrayLow];
}

For a[-3], it must return array[0].

--
ES Kim
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.