由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 帮看看这段code
相关主题
问个bb的面试题为什么我这段简单的程序segment fault
请教个java exception的问题c++ 程序一问
问一道经典C++题bloomberg assessment的机经,c语言的(20道题)
太弱了,被小印两下就灭了C++ online Test 又一题
Two C++ questions from Bloomberg on-siteC++ 一题
你们看过programming pearls (2nd edition English) or 正在看的同学们这题哪错了?
one c++ question这个看着很白痴的问题有更好的解法吗?
C的argc问题问一道kth smallest element的题目
相关话题的讨论汇总
话题: 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版参与讨论
相关主题
问一道kth smallest element的题目Two C++ questions from Bloomberg on-site
leetcode上一题,求正解你们看过programming pearls (2nd edition English) or 正在看的同学们
写了一个find kth number in 2 sorted arrays的code 请大牛看one c++ question
一题C的argc问题
问个bb的面试题为什么我这段简单的程序segment fault
请教个java exception的问题c++ 程序一问
问一道经典C++题bloomberg assessment的机经,c语言的(20道题)
太弱了,被小印两下就灭了C++ online Test 又一题
相关话题的讨论汇总
话题: type话题: catch