由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q39: throw new (C1)
相关主题
请教个java exception的问题想自学c++,现在巨土的问题问一下
问一道c++的题长期提供Twitter内推
C++ 工程师 电话面试ebay opening SJ
C++ Q53: throw (C7)帮看看这段code
实现regex(.*+)和wildcard(?*)匹配的题[合集] An interview question
select2perform上面C++测试挺头疼的Bloomberg Phone Interview
请教 C++ exception 面试问题一个CS面试题: 一个骰子最多掷三次,求最佳策略
问一道经典C++题一个c++题(exception handling)
相关话题的讨论汇总
话题: catch话题: throw话题: foo话题: caught话题: sorry
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
class A {};
class B : A {};
void foo() { throw new B; }
Which of the following catch statements successfully catches the exception
foo throws?
a) catch (A* e) and catch (B* e)
b) catch (A e) and catch (B e)
c) catch (A* e)
d) catch (B* e)
e) catch (A e)
I have no answer. Help, please.
s*********t
发帖数: 1663
2
why a is not right?
s*********t
发帖数: 1663
3
异常处理我一点不懂。
刚才试了一下,如果throw new A也不能catch B*
s*****t
发帖数: 737
4
which is subtype and super type?
I think you might be wrong. Consider the following change, what is your
answer?
class A {};
class B : A {};
void foo() { throw new A; }
Which of the following catch statements successfully catches the exception
foo throws?
a) catch (A* e) and catch (B* e)
b) catch (A e) and catch (B e)
c) catch (A* e)
d) catch (B* e)
e) catch (A e)
M******q
发帖数: 94
5
that's exactly why A* can catch new B(), i think
c**********e
发帖数: 2007
6
I think it is d). You throw a pointer to B, then you need to catch it. Here
to catch a pointer to A is not enough.
s*********t
发帖数: 1663
7
this makes perfect sense

Here

【在 c**********e 的大作中提到】
: I think it is d). You throw a pointer to B, then you need to catch it. Here
: to catch a pointer to A is not enough.

x***y
发帖数: 633
8
Sorry, you are right...A* can only be caught by A* but B* can be caught by A
* and B*...

【在 s*****t 的大作中提到】
: which is subtype and super type?
: I think you might be wrong. Consider the following change, what is your
: answer?
: class A {};
: class B : A {};
: void foo() { throw new A; }
: Which of the following catch statements successfully catches the exception
: foo throws?
: a) catch (A* e) and catch (B* e)
: b) catch (A e) and catch (B e)

x***y
发帖数: 633
9
Sorry, I made a mistacke, it should be a.

【在 s*********t 的大作中提到】
: why a is not right?
s*********t
发帖数: 1663
10
it's not a.
u just got the right answer but ur explaination wasn't

【在 x***y 的大作中提到】
: Sorry, I made a mistacke, it should be a.
x***y
发帖数: 633
11
Sorry, I made a mistake...A* can only be caught by A*, B* can be caught by A
* and B* as the thrown B* is also A* object....

【在 s*********t 的大作中提到】
: 异常处理我一点不懂。
: 刚才试了一下,如果throw new A也不能catch B*

x***y
发帖数: 633
12
It shoudl be a, my original answer is wrong....All the public inheritence
relations in c++ satisfy that the derived object is also a base object. here
, a B* is thrown, which is also a A*, that is why it can caught by both A*
and B*.
I verified in my programme and the throw new B can be caught by catch(A*).

【在 s*********t 的大作中提到】
: it's not a.
: u just got the right answer but ur explaination wasn't

x***y
发帖数: 633
13
Sorry, I made a mistacke, you are right....

【在 M******q 的大作中提到】
: that's exactly why A* can catch new B(), i think
1 (共1页)
进入JobHunting版参与讨论
相关主题
一个c++题(exception handling)实现regex(.*+)和wildcard(?*)匹配的题
请问这段代码什么意思?select2perform上面C++测试挺头疼的
【哪里有C++比较好的LinkedList实现?】请教 C++ exception 面试问题
问个简历的问题问一道经典C++题
请教个java exception的问题想自学c++,现在巨土的问题问一下
问一道c++的题长期提供Twitter内推
C++ 工程师 电话面试ebay opening SJ
C++ Q53: throw (C7)帮看看这段code
相关话题的讨论汇总
话题: catch话题: throw话题: foo话题: caught话题: sorry