I am trying to create a function which is passed a number indicating the amount of objects to create of a particular class type. While creating these objects, each should have its own pointer name so that each object can be accessed individually at any place throughout the life of the program. I was trying to name each object as 'matrixObject' and add a number in the end. For example, the first object would be matrixObject1, the second would be matrixObject2, and so on. How can I increment the digit in the pointer name while the for loop is running?
I tried using the above method. The program is returning some kind of error. When I tried debugging the program, I noticed something strange in the Autos window (I'm using Visual C++ 2005). Here's a part of my code:
1 2 3 4 5 6 7 8 9
Matrix *newMatrixPtr = new Matrix[meshDensity];
for (int n = 1; n <= meshDensity; n++)
{
meshDensity = meshDensity + 1;
newMatrixPtr[n].setRowsAndColsRunTime(meshDensity, meshDensity);
newMatrixPtr[n].AllocateMemory(meshDensity, meshDensity);
...
The Auto's window shows that newMatrixPtr and newMatrixPtr[n] have been allocated seperate memory locations. newMatrixPtr's location has a garbage value throughout the program, only newMatrixPtr[n] seems to be getting populated with the values I enter during the program.
Thanks for the correction. I did that intentionally because I wanted to associate the pointers with element numbers so that the element count could start from 1 and not 0.
I corrected the problem you identified by the actual issue was not resolved.