免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: zyb2000
打印 上一主题 下一主题

[C++] 几道C++笔试题,不定项选择,请高手解答分析,欢迎讨论。 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-11-07 01:08 |只看该作者
9, 貌似D, 继承层次多了性能自然会慢,需要遍历。
11, A, 运算符重载,返回值一定是char*, 排除b,d, 那么A,C,E 中A最有可能
16, C, 书上都有解释
17, E,同上
18,不知出处。
19,B
20,D
21,不熟悉,唉
22,B 不确定
24,E 赋值构造函数会改变被赋值函数的值,所以最后不能为const
25,D,function object,书上都有。

论坛徽章:
0
12 [报告]
发表于 2008-11-07 02:02 |只看该作者
我做的:
9. A?
11. B
16. C
17. E
18. B
19. C?
20. D
21. D
22. B
24. A
25. D

论坛徽章:
0
13 [报告]
发表于 2008-11-07 18:43 |只看该作者
原帖由 emacsnw 于 2008-11-7 02:02 发表
我做的:
9. A?
11. B
16. C
17. E
18. B
19. C?
20. D
21. D
22. B
24. A
25. D

我做了一下,不同意见的如果下:
9. B
16. AC(?)
19. BC
24. AB

论坛徽章:
0
14 [报告]
发表于 2008-11-07 21:02 |只看该作者
原帖由 emacsnw 于 2008-11-7 02:02 发表
我做的:
9. A?
11. B
16. C
17. E
18. B
19. C?
20. D
21. D
22. B
24. A
25. D

貌似是不定项,怎么大家都是单选

论坛徽章:
0
15 [报告]
发表于 2008-11-07 22:03 |只看该作者
21 D E

25 D

[ 本帖最后由 lvlv526 于 2008-11-7 22:20 编辑 ]

论坛徽章:
0
16 [报告]
发表于 2008-11-08 13:14 |只看该作者
9.   理论上讲,选B,实际上我觉得BCDE都应该选

11. char * operator(),   类型重载

18. B E.

论坛徽章:
0
17 [报告]
发表于 2008-11-08 13:44 |只看该作者
原帖由 gamania 于 2008-11-7 01:08 发表
9, 貌似D, 继承层次多了性能自然会慢,需要遍历。
11, A, 运算符重载,返回值一定是char*, 排除b,d, 那么A,C,E 中A最有可能
16, C, 书上都有解释
17, E,同上
18,不知出处。
19,B
20,D
21 ...

11, A, 运算符重载,返回值一定是char*, 排除b,d, 那么A,C,E 中A最有可能
靠, 查书了才知道,逻辑和实际不是一回事,转型运算居然不让写返回值,汗

论坛徽章:
0
18 [报告]
发表于 2008-11-09 04:59 |只看该作者
原帖由 zyb2000 于 2008-11-6 01:36 发表
9. Which of the following statements provide a valid reason NOT to use RTTI for distributed (i.e. networked between different platforms) applications in C++?
A. RTTI is too slow.
B. RTTI does not have standardized run-time behavior.
C. RTTI uses too much memory.
D. RTTI's performance is unpredictable/non-deterministic.
E. RTTI frequently fails to function correctly at run-time


谢谢各位回复!!!
该题综合了一下各位的答案,这题分歧最大:

gamania 选 D(貌似, 继承层次多了性能自然会慢,需要遍历)
emacsnw 选A(打了个问号)
tyc611    选 B (似乎比较确定)

大法师tyc611能否回答一下为什么那么确定的选B呢?RTTI不是标准的运行时行为吗?

很多书只是讲到RTTI的几个方法:typeid、static_cast、dynamic_cast,但是很少讲到内部实现的,所以也不能确定到底是不是慢或是有不可预测性。但是我理解这种run time才确定的东西,肯定要占用内存保存一些数据结构来等到runtime再调用,就像虚函数表那样。所以我实际答题的时候选了AD,但是还是不确定D该不该选。我也不清楚什么是“standardized run-time behavior”。这是我菜鸟的看法,抛砖引玉,欢迎大侠批评。

论坛徽章:
0
19 [报告]
发表于 2008-11-09 05:28 |只看该作者
原帖由 zyb2000 于 2008-11-6 01:36 发表
11. A C++ developer wants to handle a static_cast <char*>() operation for the class String shown below. Which of the following options are valid declarations that will accomplish this task?
class String {
public:
  //...
  //declaration goes here
};

A. char* operator char*();
B. operator char*();
C. char* operator();
D. String operator char*();
E. char* operator String();


看来这题迷惑了不少人,不过可能不常用所以都忘记了吧。我也不记得了。

首先在gcc上运行,只有B不报错。

其次按照C++ Primer 4th Edition Chapter 14.9的定义这是A conversion operator,关于这个重载有如下要点:

(1)A conversion function takes the general form:
operator TYPE();

TYPE represents the name of a built-in type, a class type, or a name defined by a typedef.

(2)TYPE CAN'T be void

(3)Conversions to an array or function type are NOT permitted.

(4)Conversions to pointer types both data and function pointers and to reference types are allowed.

(5)A conversion function MUST be a member function.

(6)The function may NOT specify a return type.

(7)he parameter list MUST be empty.

论坛徽章:
0
20 [报告]
发表于 2008-11-09 05:31 |只看该作者
原帖由 zyb2000 于 2008-11-6 01:36 发表
16. When a Copy Constructor is not written for a class, the C++ compiler generates one. Which of the following statements correctly describe the actions of this compiler-generated Copy Constructor when invoked?
A. The compiler-generated Copy Constructor makes the object being constructed, a reference to the object passed to it as an argument.
B. The compiler-generated Copy Constructor does not do anything by default.
C. The compiler-generated Copy Constructor performs a member-wise copy of the object passed to it as an argument, into the object being constructed.
D. The compiler-generated Copy Constructor tags the object as having been Copy-Constructed by the compiler.
E. The compiler-generated Copy Constructor invokes the assignment operator of the class.


这题疑问不大,应该选C

A如果后一句“a reference to the object passed to it as an argument”改成“a CONST reference to the object passed to it as an argument”才算对。

原帖由 zyb2000 于 2008-11-6 01:36 发表

17. Which of the following must be ensured in order to implement a polymorphic function in C++?
A.        There has to be a pointer of the derived class that has implemented the polymorphic function that holds the address of the derived class object.
B.        The function must be declared as virtual in both the base class and in the derived class that overrides the function.
C.        The function must be declared as pure virtual.
D.        There has to be a base class pointer holding the address of a base or derived class object that has implemented the polymorphic function.
E.        The function must be declared as virtual in the base class.


E没问题,蛮考语言的

[ 本帖最后由 zyb2000 于 2008-11-9 05:33 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP