Mar 4, 2013 at 7:21am UTC
Hi there!
**Edit** Solved!
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
0x0000000100002324 in std::vector<int, std::allocator<int> >::size (this=0x0) at stl_vector.h:400
400 { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
Anyone know what could be causing this?
Here's my .h file:
And here's my main file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include <iostream>
#include <cassert>
#include "deque.h"
using namespace std;
int main()
{
Deque<int > d;
d.push_back(10);
d.push_back(20);
assert(d.front() == 10);
assert(d.back() == 20);
d.push_front(1);
d.push_front(2);
d.push_front(3);
assert(d.front() == 3);
assert(d.back() == 20);
d.pop_back();
d.pop_back();
d.pop_back();
assert(d.front() == 3);
assert(d.back() == 2);
d.push_back(1);
d.push_back(0);
Deque<int >::iterator i;
int counter = 3;
for (i = d.begin(); i != d.end(); i++)
assert(*i == counter--);
for (counter = 0; counter < d.size(); counter++)
assert(d[counter] == d.size()-counter-1);
i = d.begin() + 3;
Deque<int >::iterator j(i), k;
k = j = i - 2;
assert(*k == 2);
for (i = d.begin(); not(i == d.end()); ++i)
cout << *i << " " ;
cout << endl;
d.erase(d.begin()+3);
d.erase(d.begin(), d.begin()+2);
assert(d.size() == 1);
assert(d[0] == 1);
Deque<int > c(d);
c.front() = 3;
assert(c.back() == 3);
c.push_front(1);
c.insert(c.begin(), 0);
c.insert(c.begin()+2, 2);
for (i = c.begin(); not(i == c.end()); ++i)
cout << *i << " " ;
cout << endl;
for (counter = 0; counter < c.size(); counter++)
assert(c[counter] == counter);
cout << "SUCCESS\n" ;
}
Thanks for any assistance you provide!
Last edited on Mar 4, 2013 at 7:13pm UTC
Mar 4, 2013 at 8:24am UTC
Your `iterator::operator!=' is incorrect.
By the way,
main must return int
you should compile with warnings on.
whitespace is free
Last edited on Mar 4, 2013 at 8:26am UTC
Mar 4, 2013 at 9:01am UTC
Ah thank you!
Yes, I remember when I was typing the operators that != was wrong, but forgot to go back and change it and just kept moving forwards.
Forgetting to put int before main was a typo...
Thanks for the catch! The simple things you tend to overlook!
Mar 4, 2013 at 6:26pm UTC
Alright, I solved my other problem but not I am sadly having another. Edited my original post with the new issue.