So I have a base class Animal which has 2 classes inheriting from it, which are cat and dog. Both classes are redefining a pure virtual method speak which just couts “meow” for cat and “woof” for dog. In in my main function I want to be able to do some thing like this:
int main (void) {
Animal a;
dog d;
while (cin >> a) //is this even possible? would it be cin >> d; instead?
cout << a << endl;
return(0);
}
SO this should cout the animals speak function, but how can I go about doing so? Also, I’m confused, if you dont know the type of animal the user is going to cin then how can you determine which speak function to use, would you use a template class?
Do something like this in base class:
and in derived: