I have been working in a project using matrices and graphs. The problem is when I compile it, the next line pops up:
EXC_BAD_ACCESS (code=2, address=0x7ffff5f3ffff8)
It appears in the next method; which is a constructor of my class:
GrafoMatriz::GrafoMatriz(){
maxVerts = 1;
GrafoMatriz(maxVerts);
}
typedef int * pint;
class GrafoMatriz {
...
int maxVerts;
int numVerts;
Vertice * verts; // there's another class Vertice
int ** matAd;
GrafoMatriz();
GrafoMatriz(int mx);
...
}
GrafoMatriz::GrafoMatriz (int mx){
maxVerts = mx;
verts = new Vertice[mx];
matAd = new pint[mx];
numVerts = 0;
for (int i = 0; i < mx; i++)
matAd[i] = new int[mx];
}
I have been reading about possible problems and it could be something wrong about pointers:
The pointer could have never been initialized.
The pointer could have been accidentally written over because you overstepped the bounds of an array.
The pointer could be part of an object that was casted incorrectly, and then written to.
Any of the above could have corrupted a different pointer that now points at or near this pointer, and using that one corrupts this one (and so on).
I guess it's something about my pointer pint
, but I am new to C++. So, I haven't been able to fix it. By the way0, I'm using Xcode 6.4 on an Intel Macbook Pro.