My Own Vector Class

I am creating my own vector class. I have a driver program that tests the vector class, and it is not passing Test 4. It gives me an error when I enter 1-7 or more, but if I enter 1-6 it is running fine. Not sure what exactly is wrong. I fee like I'm just skipping something simple. Any help would be great! Thanks!

http://codepad.org/4OIrq0BW

The error
Select the test you want to run:
1. Just create and destroy a Vector.
2. The above plus fill the Vector.
3. The above plus iterate through the Vector.
4. The above plus copy the Vector.
a. The extra credit test: constant and reverse iterators.
> 4
Create a Vector of floats with the default constructor.
Enter numbers, type 0.0 when done
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 0.0
Copy the contents of the Vector into a new Vector
Use the iterator to display the contents of the Vector
1.0
2.0
3.0
4.0
5.0
6.0
7.0
*** glibc detected *** a.out: free(): invalid next size (fast): 0x00000000008bb060 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3cff875e66]
/lib64/libc.so.6[0x3cff8789ba]
a.out[0x402f0c]
a.out[0x401dd1]
a.out[0x401368]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x3cff81ed5d]
a.out[0x4011c9]
======= Memory map: ========
00400000-00405000 r-xp 00000000 00:1c 11665790 /home/mar14058/cs235/Vector/a.out
00605000-00606000 rw-p 00005000 00:1c 11665790 /home/mar14058/cs235/Vector/a.out
008bb000-008dc000 rw-p 00000000 00:00 0 [heap]
3cff400000-3cff420000 r-xp 00000000 fd:00 23724037 /lib64/ld-2.12.so
3cff61f000-3cff620000 r--p 0001f000 fd:00 23724037 /lib64/ld-2.12.so
3cff620000-3cff621000 rw-p 00020000 fd:00 23724037 /lib64/ld-2.12.so
3cff621000-3cff622000 rw-p 00000000 00:00 0
3cff800000-3cff98a000 r-xp 00000000 fd:00 23724043 /lib64/libc-2.12.so
3cff98a000-3cffb8a000 ---p 0018a000 fd:00 23724043 /lib64/libc-2.12.so
3cffb8a000-3cffb8e000 r--p 0018a000 fd:00 23724043 /lib64/libc-2.12.so
3cffb8e000-3cffb8f000 rw-p 0018e000 fd:00 23724043 /lib64/libc-2.12.so
3cffb8f000-3cffb94000 rw-p 00000000 00:00 0
3d00000000-3d00083000 r-xp 00000000 fd:00 23724045 /lib64/libm-2.12.so
3d00083000-3d00282000 ---p 00083000 fd:00 23724045 /lib64/libm-2.12.so
3d00282000-3d00283000 r--p 00082000 fd:00 23724045 /lib64/libm-2.12.so
3d00283000-3d00284000 rw-p 00083000 fd:00 23724045 /lib64/libm-2.12.so
3d06000000-3d06016000 r-xp 00000000 fd:00 23724074 /lib64/libgcc_s-4.4.7-20120601.so.1
3d06016000-3d06215000 ---p 00016000 fd:00 23724074 /lib64/libgcc_s-4.4.7-20120601.so.1
3d06215000-3d06216000 rw-p 00015000 fd:00 23724074 /lib64/libgcc_s-4.4.7-20120601.so.1
3d06400000-3d064e8000 r-xp 00000000 fd:00 10234307 /usr/lib64/libstdc++.so.6.0.13
3d064e8000-3d066e8000 ---p 000e8000 fd:00 10234307 /usr/lib64/libstdc++.so.6.0.13
3d066e8000-3d066ef000 r--p 000e8000 fd:00 10234307 /usr/lib64/libstdc++.so.6.0.13
3d066ef000-3d066f1000 rw-p 000ef000 fd:00 10234307 /usr/lib64/libstdc++.so.6.0.13
3d066f1000-3d06706000 rw-p 00000000 00:00 0
7faae5381000-7faae5386000 rw-p 00000000 00:00 0
7faae53a9000-7faae53ad000 rw-p 00000000 00:00 0
7ffe3e238000-7ffe3e24d000 rw-p 00000000 00:00 0 [stack]
7ffe3e328000-7ffe3e329000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted
Last edited on
In operator=, line 76, you only create one element. You also have a memory leak in this function because you don't delete the old array.
Topic archived. No new replies allowed.