Derived class issues with arrays and casting in C++