2013-11-25

I am running into some very weird issues that have been racking my brain for the last two days. I am trying to implement part of my program polymorphically. I have a class that has an array of pointers to the base class of an inheritance hierarchy. I initialize these pointers to point to dynamically allocated objects of the respective derived classes that I need inside the class constructor. Then, I have functions that return a base class pointer that points to one of the derived class members in the aforementioned array, this allows the user to get the base class pointer and call the virtual function.

The problem is, is that when I call the function to return a base class pointer from my array of pointers, nothing happens. Like literally, nothing happens. If I include a statement such as

nothing happens, but something should happen right? These two conditions form a closed space in which the return value must either be null or non null, so how could nothing get executed? (getPlot1() returns a pointer to the first item in the array of base class pointers)

Even more weird, if I just declare a base class member in my "main", and have it point to one of my derived classes, everything works all fine and dandy just like it should. But when I declare base class pointers in a class, and then get those pointers via a member function, everything breaks down. It's really racking my brain and driving me insane

So here is the general code layout.

Here is the class that holds an array of pointers to the base class, these pointers are then initialized in the constructor to point to dynamically created derived class objects. See, I have an array of length 8 of pointers to the base class. The user can only use two of these at a time though, which is why they can use the functions setPlot1() and setPlot2() to record the index of which two plots they want to use out of the 8 available in the array. They can use getPlot1() and getPlot2() to return a pointer to the plots that they have decided to use at plot1 and plot2. The pointer returned is just one of the pointers out of the array of base class pointers.

SIMDoublePendulum.h (some stuff removed that doesn't pertain to the array of base class pointers)

Here is the implementation of the above class, so you guys can see how I'm initializing the array of base class pointers and how I'm handling them.

okay, so now here is the "main" file where I'm trying to access the base class pointer array member variable and use polymorphism to accomplish my goals. I get the SIMDoublePendulum pointer from somewhere in my program, then call getPlot1(), but this doesn't return anything. It's weird, any line of code after the line where I call getPlot1() doesn't execute at all. It's like the compiler just drops into a black hole once I call getPlot1(), but it doesn't throw any sort of error.

Show more