#include <iostream>
using namespace std;
class father {
public:
father() {}
~father() {}
virtual void func1() {
func2();
}
virtual void func2() {
cout << "AAAAA";
}
};
class son : public father {
public:
son() {}
~son() {}
void func1(int i) {
cout << "BBBBB";
}
void func2() {
cout << "CCCCC";
}
};
int main() {
father* fa = new son();
fa->func1();
// son* son = new father(); // 禁止的操作,父类指针可以指向子类对象,子类指针不能指向父类对象
return 0;
}
输出:
CCCCC
总结参考:https://blog.csdn.net/u010164190/article/details/104507528/