(Relevant to this question.)
I have a base class Base
and two derived classes, Der1
and Der2
. (See linked question for basic implementation. Each has a number of public properties as well.) In my program I create an array of Base
like this:
Base *array[10];
int count = 0; // program-wide count of how many objects are in the array
Then later on I fill it with instances of Der1
and Der2
as follows:
Der1 d = Der1();
d.x = 0; // Filling in public properties
d.y = 1;
d.z = 3;
array[count] = &d;
count++;
Near-identical code is used for Der2
.
Much later, I use the array to call on functions defined in those classes:
int result = array[i]->SomeFunction(x, y);
My code compiles fine, but when I try to run it I get "Unhandled exception at 0x00232d60 in program.exe: 0xC000005: Access violation reading location 0x04064560."
When I take a look at the object in the array I'm trying to access, all of the properties' values are 0.0000 instead of what they're supposed to be. There are also two double
-type arrays and it looks like the last few elements are uninitialized ("1.572398880752e-311#DEN" or "-9.2559631349317831e+061" or similar).
I've been doing .NET too long and have forgotten a lot of what I knew about pointers, which I'm assuming is the source of my problem... Any suggestions on how I can fix this error?