What is the output of the following code? Why?
#include
using namespace std;
class base {
public:
void pay() { cout << "Base::pay" << endl; }
virtual void eat() { pay(); }
};
class derived: public base {
public:
void pay() { cout << "Derived::pay" << endl; }
};
void main() {
base* p = new derived;
p->eat();
}
r*******y 发帖数: 1081
2
Base::pay
【在 c**********e 的大作中提到】 : What is the output of the following code? Why? : #include : using namespace std; : class base { : public: : void pay() { cout << "Base::pay" << endl; } : virtual void eat() { pay(); } : }; : class derived: public base { : public: