若有如下类,则执行语句 A *a=new B(10); delete a;输出结果为()。
class A{
public:
virtual ~A{ cout<
};
class B:public A{
char *buf;
public:
B(int i) { buf=new char[i]; }
virtual ~B{
delete []buf;
cout<
}
};
class A{
public:
virtual ~A{ cout<
};
class B:public A{
char *buf;
public:
B(int i) { buf=new char[i]; }
virtual ~B{
delete []buf;
cout<
}
};
举一反三
- 有如下程序: #include<iostream> using namespace std; class A public: virtual void func1()cout<<"A1"; void func2()cout<<"A2"; ; class B:public A public: void func1()cout<<"B1"; void func2()cout<<"B2"; ; int main() A: A*p=new B; B: p->func1(); C: p->func2(); D: delete p; E: retum 0;执行这个程序的输出结果是______。A.B1B2 F: A1A2 G: B1A2 H: A1B2
- 下列程序运行结果是 。class A{public:virtual void funcl(){cout[< "A1";}void func2(){cout<< "A2";}};class B: public A{public:void func1(){cout<< "B1";}void func2(){cout<< "B2";}};int main(){A *p=new B;p-]funcl();p->func2();return 0;}
- 有如下程序:#include[iostream.h] class A { public: virtual void func1( ){cout[<"A1";} void func2( ){cout<<"A2";} }; class B:public A { public: void func1( ){cout<<"B1";} void func2( ){cout<<"B2";} }; void main( ) { A *p=new B; p-]func1( ); p->func2( ); }执行该程序,屏幕上将显示输出( )。 A: B1B2 B: A1A2 C: B1A2 D: A1B2
- 有如下程序: #include<iostream> using namespace std; class A public: A: A() cout<<"A"; B: ~A() cout<<"~A"; C: ; D: class B:public A E: A*p; F: public: G: B() cout<<"B";p=new A; H: ~B() cout<<"~B";delete p; I: ; J: int main()B obj; K: return 0;执行这个程序的输出结果是( L: )A) BAA~A~B~A M: B) ABA~B~A~A N: C) BAA~B~A~A O: D) ABA~A~B~A
- 下列虚基类的声明中正确的是( )。 A: class virtual B:public A B: virtual class B:public C: class B:public A virtual D: class B: virtual public A