我有这个代码示例,我想了解它为什么会这样做.这是一篇介绍C++课程中过去的试卷的问题.我现在正在为考试而学习,并试图巩固我对班级继承的理解.
#include <iostream>
using namespace std;
class Bird {
public:
virtual void noise() { cout << "mumble" << endl; }
void move() { noise(); cout << "fly" << endl; }
};
class Canary: public Bird {
public:
void noise() { cout << "chirp" << endl; }
void move() { noise(); cout << "flap" << endl; }
};
class Tweety: public Canary {
public:
void noise() { cout << "tweet" << endl; }
void move() { noise(); cout << "run" << …Run Code Online (Sandbox Code Playgroud)