Hello.
I have 2 classes, one is the base (bibliorafia) ad the other the derived class (sinedria).
I want to create an array of pointers that start as the type of the base and then change it to the type of the derived. What i mean is the following code:
1 2 3 4
|
bibliografia *test;//bibliografia is the base class and sinedria is the derived
test = new sinedria[2];
test[0].probolh();//probolh() is a function to display the contents of the class
test[1].probolh();
| |
This compiles perfect but every time I run it it has a problem going to test[1].probolh()...The program stops responding before entering the probolh() function because the windows prevent its execution as probable harming. Which, as i understand, means that my program is trying to read a memory location outside of the program.
I added some cout's to see the process and i found out that when I enter the data to the derived class (through the constructor) they are correct. But the problem occurs when i try to call it and retrieve the data. Then all the values are incorect (like random) and they cause an array to go out of bounds.
If i don't use array (test = new sinedria)or if the pointer is from the beggining only as the derived type then it works fine, but I want to do it as the base class because after that i will make more derived classes and i want to have them all in a 2D array.
Do you know if there is any way to do something like that?
Thank you in advance.