哎,又是NOIP的一天
#include<bits/stdc++.h>
using namespace std;
class BaseClass{
public:
BaseClass(){}
void f(char *s="unknown"){
printf("Function f() in BaseClass called from %s\n",s);
h();
}
protected:
void g(char *s="unknown"){
printf("Function g() in BaseClass called from %s\n",s);
}
private:
void h(char *s="unknown"){
printf("Function h() in BaseClass %s\n",s);
}
};
class Derived1Levell:public virtual BaseClass{
public:
void f(char *s="unknown"){
printf("Function f() in Derived1Levell called from %s\n",s);
g("Derived1Levell");
h("Derived1Levell");
}
void h(char *s="unknown"){
printf("Function h() in Derived1Levell called from %s\n");
}
};
class Derived2Levell:public virtual BassClass {
public:
void f(char *s="unknown"){
printf("Function f() in Derived2Levell called from %s\n",s);
g("Derived2Levell");
//h();//error:BassClass::h() is not accessible
}
};
class DerivedLevell2:public Derived1Levell,public Derived2Levell{
public:
void f(char *s="unknown"){
printf("Function f() in DerivedLevell2 called from %s\n");
g("DerivedLevell2");
Derived1Levell::h("DerivedLevell2");
BassClass::f("DerivedLevell2");
}
};
int main(){
BassClass bc;
Derived1Levell d1l1;
Derived2Levell d2l1;
DerivedLevell2 dl2;
bc.f("main(1)");
d1l1.f("main(2)");
d1l1.h("main(3)");
d2l1.f("main(4)");
dl2.f("main(5)");
dl2.h();
return 0;
}
全部评论
(0) 回帖