#include <vector>
#include <string>
#include <iostream>
using namespace std;
class A{
public:
virtual void func(int i=1){
cout<<"A->"<<i<<endl;
}
virtual void test(){
func();
}
};
class B:public A{
public:
void func(int i=0){
cout<<"B->"<<i<<endl;
}
};
int main()
{
B *b = new B;
b->test();
//结果B-〉1因为调用的是A的环境,默认参数在A中的值
return 0;
}
虚函数调用
最新推荐文章于 2024-08-01 17:11:41 发布