作业帮 > 综合 > 作业

class underflow

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 01:59:36
class underflow
{
public:
underflow:message("underflow"){}
private:
char *message;
}
class Text
{
.
void push();
.
}
void Text::push()
{
.
throw underflow();
.
}
这里我就不明白了,throw underflow()是抛出异常,那为什么会是类名直接加(),这个underflow执行了什么?我从来没见过这个用法,
throw underflow(); underflow()调用underflow的构造函数构造了一个临时对象.这个对象在push函数结束后就消失了.
当然如果下面catch语句,就会把临时对象的副本传到catch中.
Text t;
try
{
t.push();
}
catch(underflow e)//得到临时对象的副本
{
//处理动作.
}