boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 帮看看这段code
相关主题
问个bb的面试题
请教个java exception的问题
问一道经典C++题
太弱了,被小印两下就灭了
Two C++ questions from Bloomberg on-site
你们看过programming pearls (2nd edition English) or 正在看的同学们
one c++ question
C的argc问题
为什么我这段简单的程序segment fault
c++ 程序一问
相关话题的讨论汇总
话题: type话题: catch
进入JobHunting版参与讨论
1 (共1页)
m******e
发帖数: 481
1
这段code有什么问题?
Thanks
struct Exception
{
virtual int Type(){ return 0;}
};
struct ExceptionChild:Exception
{
virtual int Type(){ return 1;}
};
int _tmain(int argc, _TCHAR* argv[])
{
try
{
throw ExceptionChild();
}
catch(ExceptionChild e)
{
printf("Type value %d", e.Type());
}
return 0;
}
m******e
发帖数: 481
2
Correct the grammer problem from typing in OP
Interviewer did say there is problem
l*****a
发帖数: 14598
3
you should use catch by reference
for details, please read more effective C++

【在 m******e 的大作中提到】
: 这段code有什么问题?
: Thanks
: struct Exception
: {
: virtual int Type(){ return 0;}
: };
: struct ExceptionChild:Exception
: {
: virtual int Type(){ return 1;}
: };

m******e
发帖数: 481
4
Thanks. find it
The standard practice for exceptions in C++ is ...
Throw by value, catch by reference
Catching by value is problematic in the face of inheritance hierarchies.
Suppose for your example that there is another type MyException which
inherits from CustomException and overrides items like an error code. If a
MyException type was thrown your catch block would cause it to be converted
to a CustomException instance which would cause the error code to change.
References

【在 l*****a 的大作中提到】
: you should use catch by reference
: for details, please read more effective C++

l*****a
发帖数: 14598
5
catch by value will generate a local copy, will cause type slice
catch by pointer may need to think whom to delete the pointer
also the 4 basic std expections are not a pointer

converted

【在 m******e 的大作中提到】
: Thanks. find it
: The standard practice for exceptions in C++ is ...
: Throw by value, catch by reference
: Catching by value is problematic in the face of inheritance hierarchies.
: Suppose for your example that there is another type MyException which
: inherits from CustomException and overrides items like an error code. If a
: MyException type was thrown your catch block would cause it to be converted
: to a CustomException instance which would cause the error code to change.
: References

m*****a
发帖数: 636
6
catch的已经是ExceptionChild了,
也还用reference嘛?

Thanks. find it
The standard practice for exceptions in C++ is ...
Throw by value, catch by reference
Catching by value is problematic in the face of inheritance hierarchies.
Suppose for your example that there is another type MyException which
inherits from CustomException and overrides items like an error code. If a
MyException type was thrown your catch block would cause it to be converted
to a CustomException instance which would cause the error code to change.
References

【在 m******e 的大作中提到】
: Thanks. find it
: The standard practice for exceptions in C++ is ...
: Throw by value, catch by reference
: Catching by value is problematic in the face of inheritance hierarchies.
: Suppose for your example that there is another type MyException which
: inherits from CustomException and overrides items like an error code. If a
: MyException type was thrown your catch block would cause it to be converted
: to a CustomException instance which would cause the error code to change.
: References

m******e
发帖数: 481
7
"the 4 basic std expections are not a pointer
What does this mean?
Thanks

【在 l*****a 的大作中提到】
: catch by value will generate a local copy, will cause type slice
: catch by pointer may need to think whom to delete the pointer
: also the 4 basic std expections are not a pointer
:
: converted

l*****a
发帖数: 14598
8
could u read more effective c++ Item13?

【在 m******e 的大作中提到】
: "the 4 basic std expections are not a pointer
: What does this mean?
: Thanks

p*********t
发帖数: 2690
9
throw MyException();
catch (CustomException& x)
这样不会引起late binding吗?

converted

【在 m******e 的大作中提到】
: Thanks. find it
: The standard practice for exceptions in C++ is ...
: Throw by value, catch by reference
: Catching by value is problematic in the face of inheritance hierarchies.
: Suppose for your example that there is another type MyException which
: inherits from CustomException and overrides items like an error code. If a
: MyException type was thrown your catch block would cause it to be converted
: to a CustomException instance which would cause the error code to change.
: References

p*********t
发帖数: 2690
10
如果 catch()里面已经是exceptionChild的话,不用reference也行,多用一次copy
constructor而已.

converted

【在 m*****a 的大作中提到】
: catch的已经是ExceptionChild了,
: 也还用reference嘛?
:
: Thanks. find it
: The standard practice for exceptions in C++ is ...
: Throw by value, catch by reference
: Catching by value is problematic in the face of inheritance hierarchies.
: Suppose for your example that there is another type MyException which
: inherits from CustomException and overrides items like an error code. If a
: MyException type was thrown your catch block would cause it to be converted

1 (共1页)
进入JobHunting版参与讨论
相关主题
c++ 程序一问
bloomberg assessment的机经,c语言的(20道题)
C++ online Test 又一题
C++ 一题
这题哪错了?
这个看着很白痴的问题有更好的解法吗?
问一道kth smallest element的题目
leetcode上一题,求正解
写了一个find kth number in 2 sorted arrays的code 请大牛看
一题
相关话题的讨论汇总
话题: type话题: catch