473,386 Members | 1,821 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,386 software developers and data experts.

Strange Results with Overloaded Operators

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
5 1432

"- 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
"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
"- 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
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
"- 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: ...
20
by: Brad Eck | last post by:
"The only operators that cannot be overloaded are :: (scope resolution), . (member selection), and .* (member selection through pointer to function). Quoting from Stroustrup's 3rd edition of _The...
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
4
by: masood.iqbal | last post by:
Please help me with this doubt that I have regarding overloaded operators. Sometimes they are member functions and sometimes they are friends (e.g. see the code snippet from Stroustrup, Second...
10
by: maadhuu | last post by:
hi i wasnt to know the answer for the following. now ,u can overload all the operators which are basically determined at runtime (coz' of whch operators like sizeof())cannot be overloaded. now...
14
by: ambar.shome | last post by:
Hi, As you know there are few operators in C++ which cant be overloaded. They are: .., .*, ::, ?: , new , delete , sizeof , typeid , static_casr , dynamic_cast , const_cast ,...
1
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type...
13
by: olanglois | last post by:
Hi, I am trying to derive a new class that will add new functions but no new data members and the base class has overloaded operators (+,-,+=,-=,etc...) returning either (Base &) or (const Base)...
3
by: iluvatar | last post by:
Hi all. I have written a 3d-vector class (for 3-dimensional space) and I have overloaded the arihtmetic operators like +, +=, * and so on. Also, the constructor works with doubles and has...
4
by: Daniel Kraft | last post by:
Hi all, I'd like to know your opinion on when you think overloaded operators should/could be used instead of "ordinary methods". Of course, they are essential for generic programming and there...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.