I have an Abstract class, say Animal. From this class, I have many inheriting classes, such as Cat, Dog, Mouse. I have a method that I want to be able to take pointers to pointers of these objects. So void someMethod(Animal **anAnimal);
How is this accomplished? It seems I am not able to cast upwards like this. I am trying the following:
Dog *d = new Dog(x); //some parameter x.
Animal **animal = &d;
someMethod(animal);
//where someMethod has the method signature...
void someMethod(Animal **anAnimal);
What am I doing wrong, and how can I accomplish what I’m attempting?
You need an
Animal*:An
Animal**can only point to anAnimal*. It would be very bad if it could point to aDog*. If it could, you could do something like this:Now
dpoints to aHippopotamus, which is very wrong indeed.