int a,b; };
class B: public A { public:
B(int i,int j,int k,int l):A(i,j),x(k),y(l){} void Show(){coutvvxvv '\void fun(){Move(3,5);} void f1(){A::Show();} private:
int x,y; };
int main() {
A e(1,2); e.Show(); B d(3,4,5,6); d.fun(); d.A::Show(); d.B::Show(); d.f1(); return 0; }
运行结果:(1,2)
(6,9) (5,6) (6,9)
4、阅读程序,回答下列问题。
class A {
public: void f(); };
class B:virtual public A {
public: void f(); };
class C:public B { };
class D:public C,virtual public A { public:
void g(); }; (1) (2)
设有 D d ;问:d.f()是否有二义性? 设有
void D::g() {
f();
}
问:g()函数中对f()调用是否有二义性?
5、阅读程序,写出执行结果并进行简要分析。 #includeviostream> using namespace std; class P {
public:
P(int p1,int p2){pri仁p1;pri2=p2;} int inc1(){return ++pri1;} int inc2(){return ++pri2;}
void display(){coutvv \仁''vvpri1vv \int pri1,pri2;
};
class D1:private P {
public:
D1(int p1,int p2,int p3):P(p1,p2) {
pri3=p3; }
int inc1(){return P::inc1();} int inc3(){return ++pri3;} void display() {
P::display();
coutvv \} private:
int pri3;
};
class D2:public P {
public:
D2(int p1,int p2,int p4):P(p1,p2) {
pri4=p4; }
int inc1() P::inc1(); P::inc2();
return P::inc1();
int inc4(){return ++pri4;} void display。 {
P::display();
cout<<\} private:
int pri4;
};
class D12:private D1,public D2 { public:
D12(int p11,int p12,int p13,int p21,int p22,int p23,int
p):D1(p11,p12,p13),D2(p21,p22,p23) { pri12=p; }
int inc1() {
D2::inc1(); return D2::inc1(); }
int inc5() {return ++pri12;} void display() {
coutvv\D2::display()\\n D2::display();
coutvv \pri12= \vvpri12vvendl; } private:
int pri12; };