Archived

This topic is now archived and is closed to further replies.

stenton13

My object properties keep getting overwritten!!

Recommended Posts

Im making an AI application, using a 2 dimensional array of cell objects to draw a "grid" to the screen (in OpenGL). Like I said, each cell is an object, and has a "value" property which im trying to assign now. The values assigned to the cells are read from a series of 1 dimensional arrays. Currently Im trying to assign values to one row of cells at a time. However, when i come to assign the second row values I find that the 1st row values have been overwritten....I have no idea why! Can somebody take a look at the code below and offer any suggestions....? //This is where I create the 2D array (grid) of cell objects. cell grid[16][11]; //Here Im assigning values to the 1st two "line" arrays, ready to be copied to the cell value property. int line0[11]= { 1,1,2,1,1,1,1,2,1,1,1}, line1[11]= { 1,1,2,1,1,1,3,3,1,1,1}, //This is where I loop through from 1 to 11 setting the value for each cell in the 1st row, then the second row. The cout statements always show that the second rows values overwrite the 1st. If i comment out the setvalue stuff for the second line, the 1st rows values print out fine. It must be getting overwritten. Is my syntax correct? for (int i=0; i < 11; i++){ grid[0].setvalue(line0[i]); grid[1][i].setvalue(line1[i]); //cout << "value from line 0: " << grid[0][i].returnvalue() << endl; cout << "value from line 1: " << grid[1][i].returnvalue() << endl;

Share this post


Link to post
Share on other sites
Everything looks fine. Copy and paste your code, including your cell class, to see if the error is somewhere else.

ps. Use source tags to display code. Since you put an i in square brackets, the forum took to mean italics.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
Symptoms you describe are usually do to overrunning your buffer into other memory space. You''re probably going past the end of an array somewhere and writing into whatever''s next to it.

Share this post


Link to post
Share on other sites