下列程序编译时发现pb->f(10);语句出现错误,其原因是______。
include<iostream.h>
class Base
{
public:
void f(int x){cout<<"Base:"<<x<<endl;)
};
class Derived:public Base
{
public:
void f(char*str){cout<<"Derived:"<<str<<endl;}
};
void main(void)
{
Derived*pd=new Derived;
Pd->f(10);
}
第1题:
下列程序如果去掉for循环外围的大括号对,则会出现编译错误。错误原因是______。
include<iostream.h>
int a=5;
void main( )
{
int a=10,b=20;
cout<<a<<","<<b<<endl;
{
int a=0,b=0;
for(int i=1;i<8;i++)
{
a+=i;
b+=a;
}
cout<<a<<","<<b<<","<<::a<<endl;
}
cout<<a<<","<<b<<endl;
}
第2题:
在下列的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
using namespace std;
class Base
{
public:
int a,b;
Base(int i){a=i;}
};
class Derived:public Base
{
int a;
public:
Derived(int x):Base(x),b(x+1){};
void show()
{
第3题:
按解释中的要求在下列程序划线处填入的正确语句是:() #include <iostream.h> 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题:
为使程序的输出结果为: Base:: fun 那么应在下列程序画线处填入的正确语句是( )。 #include <iostream> using namespace std; class Base { public: void fun () { cout<<"Base: :fun"<<end1; } }; class Derived : public Base { public: void fun ( ) { cout<<"Derived: :fun"<<end1; } }; int main ( ) { Base a,*pb; Derived b; _________; pb->fun(); //调用基类的成员函数 fun() return 0 ; }
A.pb=&a
B.pb=b
C.pb=&b
D.pb=&Base
第5题:
如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。
include<iostream.h>
class test
{
private:
int hum;
public:
test(int);
void show( );
};
test::test(int n){num=n;}
test::show( ){cout<<num<<endl;}
void main( )
{
test T(10):
T.show( );
}