Return the address of a polymorphic object using a virtual function
up vote
0
down vote
favorite
I have a polymorphic list of objets vector<Animal*> my_pets and my animal can be i.e a cat, a dog,or a tortoise. My dog or toirtoise have to point on a specific cat on the polymorphic list. my_pets.push_back(new Cat()) my_pets.push_back(new Dog(my_pets[0]->getAddress()); my_pets.push_back(new Tortoise(my_pets[0]->getAddress()); So the dog and the tortoise have to receive the address of the cat. The problem is that I don't know how to write the function(getAddress()) to get this address. I wanted to make a virtual function getAddress() so that I could use it in my polymorphic list but I struggle to get the right way to do that anybody could help please ?
pointers polymorphism