I have written a custom vector class for an assignment, and am having trouble with the driver code. I created the push_back function the first code. Then in the second is the first test with the push_back. I can't seem to make both driver codes accurate.
Either the first one prints out an extra number (i think an address) or the size is not accurate on the second driver code. I can't seem to find out where this error is happening. I would really appreciate any advice.
for (int i = 0; i < sam.size() + 1; i++)
Why + 1?
Take into consideration an empty "sam".
Size should be 0.
If you add a 1, you are "faking" an element which is not there.
If you want the exception to be thrown and handled, show us the MyVector::at code.
The problem should be there.
Oh yeah! And because of you I know more what i'm looking for! Thank you so much! It uses size + 1 so it will throw an exception. So I have figured out the program is working except i'm not catching the exception correctly.