对于下面程序,对p进行赋值正确的是( )。 class A{ public:fun(int i){cout<<i<<endl;} }; main(){ void(A::*p)(int); }
A.p=fun;
B.p=fun();
C.p=A::fun;
D.p=A::fun()
第1题:
下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }
A.new file open file save file
B.new file new file new file
C.编译出错
D.open file new file save file
第2题:
下面程序的运行结果是( )。 #include<iostream> using namespace std; class A { public: virtual~A() { cout<<"call A::~A()"<<endl;} }; class B:public A { char * p; public: B(int i) { p=new char[i];} ~B() { delete(p); cout<<"call B::~B()"; } }; void main() { A * a=new B(8); delete a; }
A.call B::~B()call A::~A()
B.call B::~B()
C.call A::~A()
D.call A::~A()call B::~B()
第3题:
下列程序划线处应填入的正确语句是()。 class Base { public: void fun(){ cout<<"Base::fun"<<endl; } }; class Derived:public Base { public: void fun() { _____________ //显示调用基类的函数fun() cout<<"Derived::fun"<<endl; } };
A.fun();
B.Base.fun();
C.Base::fun();
D.Base->fun();
第4题:
对于下面程序,对p调用正确的是( )。 class A{ public:fun(int i){cout<<i<<endl;} }; main(){ A a; int k=0; void(A::*p)(int); p=A::fun; }
A.a.p(k);
B.*a.p(k)
C.a.*p(k)
D.a::*p(k)
第5题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
virtual void func(int i){cout<<"class Base:"<<i<<end1;)
};
class Derived: public Base
{
public:
void func(double d){cout<<"class Derived:"<<d<<endl;}
};
void main( )
{
Base a,*p=a;
Derived b;
p=&b;
(*p).func(3.3);
}