Thanks MiiNiPaa for your prompt reply. Let me try to respond:
You wrote: "What if lower bound is 9 and upper bound is 100? You will create an array of size 1, but will try to access 99th element."
Did you mean to write 10 and not 100? 'Cause that's the only way the array size would result in 1.
Also you wrote: "Also problem with negative elements." Did you mean negative elements of the array OR negative parameters at object declaration? Anyways, the index of arrayPtr (= i) can never be negative, given some object declaration constraint (e.g. upperBound>lowerBound) and the way I wrote the constructor.
The constructor is definitely not the problem; like I implied in my earlier post, the objects of the class were successfully created (for integer, double, and string datatypes); it's the assignment operation that's failing me, I'm guessing. Here are my constructor and the overloaded operator you asked for:
myArray<dataType>::myArray(int lowerBound, int upperBound)
if (upperBound == 0)
arrayLowerBound = 0;
arrayUpperBound = lowerBound;
arrayLowerBound = lowerBound;
arrayUpperBound = upperBound;
arraySize = arrayUpperBound - arrayLowerBound;
arrayPtr = new dataType[arraySize];
dataType& myArray<dataType>::operator(int index)
if (arrayLowerBound <= index && index < arrayUpperBound)
cout<<"Array index out of bound!! Bailing out!"<<endl<<endl<<endl;
// wait until user is ready before terminating program
abort(); //terminates program due to erroneous array index
assert(arrayLowerBound <= index && index < arrayUpperBound);
By the way, I'm jealous of the way you captured the exact fonts/color of my program segment. Yours even had line numbers! So cool! How do I go about doing that on here; I'm fairly new to the forum. Thanks.