找考题网-背景图
未分类题

有如下程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<'print1'<<end1; } void print()const { cout<<'print2'<<end1; } }; int main() { const TestClass a(1,2); A.print(); return 0; } 该程序运行后的输出结果是( )。
A.print1
B.print2
C.print1 print2
D.程序编译时出错

A.print();
B.print1
B.print2
C.print1

【参考答案】

B
解析:由主函数main入手,定义TestClass型的常对象a,然后调用对象a中的成员函数print()。因为在C++中,如果一个对象被声明为常对象,则不能调用该对象中的非const型的成员函数。所以,这里调用的是对象中的const型成员函数“void print()const”,输出为......

(↓↓↓ 点击‘点击查看答案’看完整答案 ↓↓↓)
热门试题

未分类题Culture is the sum total of all the traditions, customs, beliefs, and ways of life of a given group of human beings. In this (1)_____, every group has a culture, however un-developed or uncivilized it may seem to us.To the professional anthropologist, there is no intrinsic superiority of one culture (2)_____ another, just as to the professional linguist there is no intrinsic (3)_____ among the different languages.People once (4)_____ the languages of backward groups as savage, undeveloped (5)_____ of speech, consisting largely of grunts and groans. (6)_____ it is possible that language (7)_____ began as a series of grunts and groans, it is a fact established by the study of 'backward' languages (8)_____ no spoken tongue answers that description today. Most languages of (9)_____ groups are, by our most severe standards, extremely (10)_____, delicate, and ingenious pieces of machinery for the transfer of ideas. They (11)_____ behind our Western languages not in their sound patterns or grammatical structures, which usually are fully adequate for all language needs, (12)_____ only in their vocabularies, which reflect their speakers' social (13)_____.Even in this department, (14)_____, two things are to be noted: 1) All languages seem to (15)_____ the machinery for vocabulary expansion, either by putting together words already in existence (16)_____ by borrowing them from other languages and adapting them to their own system. 2) The objects and activities requiring names and (17)_____ in 'backward' languages, while different from ours, are often (18)_____ numerous and complicateD.A Western languages distinguishes merely between two degrees of remoteness ('this' and 'that'); some languages of the American Indians distinguish between what is close to the speaker or to the person (19)_____ and what is removed from both, or out of sight, or in the past, or in the futurE.This study of language, in turn, (20)_____ a new light upon the claim of the anthropologists that all cultures are to be viewed independently, and without ideas of rank.A.perspectiveB.senseC.dimensionD.manner

A.B.
C.
D.
E.
A.perspective
B.sense
C.dimension