c++ reading an array of objects causes SIGSEGV -
I have two squares: vector and particle ...
square vector {public : Float X, Y; }; Square particle {public: vector * sync; Particle (vector * sync) {it-> coordinate = coordination; }; }; ... and an array declared like this:
particle * particle [particle]; This is my main one:
int main (int argc, char ** argv) {// write I = 0; Do {particle [i] = new particle (new vector ()); } While (++ i & lt; particle); I = 0; // read et j = 0; Float s = .0f, a = .0f; Vector Vi = * (particle [0] -> coordinate), VJ = * (particle [0] -> sync); Do {{(if (i! = J) {vi = * (particle [i] -> coordinate); VJ = * (particle [ja] -> coordinate); // FIXME}} while (+ + J & lt; Episodes // for values, 1 throws SIGSEGV;}} while (++ i & lt; particle); return 0;} This is a SIGSEGV Throws whenever the particle is> by commenting that FIXME line works without errors. Full code here:
This Why is it unsuccessful and there is a way to fix it?
thanks :)
Loop has been written incorrectly. j is not reset before the second instance of the internal loop why do not you code the loop like most people: for (i = 0; I & lt; particle; i ++) {for (j = 0; j & lt; particle; j ++) {// ...}}
Comments
Post a Comment