下面代码执行后的输出结果为?
#include <iostream>
using namespace std;
class Animal {
public:
void eat() {
cout << "1" << endl;
}
virtual void drink() {
cout << "2" << endl;
}
};
class Dog : public Animal {
public:
void eat() {
cout << "3" << endl;
}
void drink() {
cout << "4" << endl;
}
};
int main() {
Animal ani;
Dog dog;
Animal *p = &ani;
p->eat();
p->drink();
p = &dog;
p->eat();
p->drink();
Animal *ptr = (Animal*)&dog;
ptr->eat();
ptr->drink();
return 0;
}