I want to store few animals in a vector. Animals may be Cats or Dogs. Later I want cats and dogs back from the vector. Can I use type casting here?
eg.
class Animal{
string name;
void makeSound();
}
class Dog:public Animal{
string owner;
void makeSound(){
cout << "Woof";
}
class Cat:public Animal{
string home;
void makeSound(){
cout << "Mew";
}
in main program.
vector<Animal> list;
Cat c = Cat();
list.push_back(c);
Cat cat = (Cat)list.at(0); // how can I do this
PS:
This is not the exact code with syntax. But I need to do something like this.