问题 单项选择题

有如下程序:
#include<iostream>
using namespace std;
class B
public:
virtual void show( )cout<<"B";

class D:public B
public:
void show( )cout<<"D";

void funl(B*ptr)ptr->show( );
void fun2(B&ref);ref.show( );
void fun3(B b)b.show( );
int nlain( )
B b,*P=Dew D;
D d;
funl(p);
fun2(b);
fun3(d);
return 0;

程序的输出结果是

A.BBB

B.BBD

C.DBB

D.DBD

答案

参考答案:C

解析: 基类指针可以指向派生类对象,在对象作为参数传递时,是通过“传值调用”传递给函数的,是单向传递。使用对象指针对函数参数进行传递时,是通过“传址调用”传递给函数的,即函数的形参对象和实参对象指针变量指向同一内存地址;使用对象引用作为函数参数时,也是通过“传址调用”传递给函数的。funl(p)传递的是类D对象的地址,所以调用类D的是show( ),fun2(b)调用的和传递的都是类B的对象引用,所以调用类B的show( )。调用’fun3(d)时,由于void fun3(B b)传递的虽然是D类对象,但是形参是B类对象,所以调用基类B的show( )。

阅读理解

Many teenagers feel that the most important people in their lives are their friends. They believe that their family members, especially their parents, don’t know them as well as their friends do. In a large family, it is quite often for brothers and sisters to fight with each other and then they only go to their friends for getting ideas.

It is very important for teenagers to have one good friend or a circle of friends. Even when they are not with their friends, they usually spend a lot of time talking among them on the phone. This communication is very important in children’s growing up, because they can not discuss something difficult to their family members.

Parents often try to choose their children’s friends for them.Some parents may even stop their children from meeting their good friends: The question of “choice” is an interesting one. Have you ever thought of the following questions?

    Who choose your friends?

Do you choose your friend or your friends choose you?

Have you got a good friend your parents don’t like?

Your answers are welcome.

小题1:Who know them better than their parents for the teenagers?

A.Their parents.

B.Their friends.

C.Brothers and sisters.

D.Family members.小题2:How do they communicate when the teenagers stay alone?

A.Go to their friends.

B.Talk with their parents:

C.Talk with their friends on the phone.

D.Have a discussion with their family by phone.小题3:Which of the following sentences is true?

A.Parents should like everything their children enjoy.

B.In all families, children can choose everything they like.

C.Teenagers can only go to their friends for help.

D.Parents should try their best to understand their children better.小题4:What is the meaning for “Your answers are welcome. ”?

A.You are welcome to have a discussion with us.

B.You have got an idea, so your answers are welcome.

C.Your answers are always right.

D.You can give us all the right answers.小题5:. Which is the best title of this passage?

A.Only parents can decide.

B.Parents and children.

C.A strange question.

D.Teenagers need friends.

单项选择题