class underflow{public:underflow:message("underflow"){}private:char *message;}class Text{.void push();.}void Text::push(){.throw underflow();.}这里我就不明白了,throw underflow()是抛出异常,那为什么会是类名直接加(),这个underfl
来源:学生作业帮助网 编辑:作业帮 时间:2024/09/09 03:26:41
![class underflow{public:underflow:message(](/uploads/image/z/14155189-61-9.jpg?t=class+underflow%7Bpublic%3Aunderflow%3Amessage%28%22underflow%22%29%7B%7Dprivate%3Achar+%2Amessage%3B%7Dclass+Text%7B.void+push%28%29%3B.%7Dvoid+Text%3A%3Apush%28%29%7B.throw+underflow%28%29%3B.%7D%E8%BF%99%E9%87%8C%E6%88%91%E5%B0%B1%E4%B8%8D%E6%98%8E%E7%99%BD%E4%BA%86%2Cthrow+underflow%28%29%E6%98%AF%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%2C%E9%82%A3%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BC%9A%E6%98%AF%E7%B1%BB%E5%90%8D%E7%9B%B4%E6%8E%A5%E5%8A%A0%28%29%2C%E8%BF%99%E4%B8%AAunderfl)
class underflow{public:underflow:message("underflow"){}private:char *message;}class Text{.void push();.}void Text::push(){.throw underflow();.}这里我就不明白了,throw underflow()是抛出异常,那为什么会是类名直接加(),这个underfl
class underflow
{
public:
underflow:message("underflow"){}
private:
char *message;
}
class Text
{
.
void push();
.
}
void Text::push()
{
.
throw underflow();
.
}
这里我就不明白了,throw underflow()是抛出异常,那为什么会是类名直接加(),这个underflow执行了什么?我从来没见过这个用法,
class underflow{public:underflow:message("underflow"){}private:char *message;}class Text{.void push();.}void Text::push(){.throw underflow();.}这里我就不明白了,throw underflow()是抛出异常,那为什么会是类名直接加(),这个underfl
throw underflow(); underflow()调用underflow的构造函数构造了一个临时对象.这个对象在push函数结束后就消失了.
当然如果下面catch语句,就会把临时对象的副本传到catch中.
Text t;
try
{
t.push();
}
catch(underflow e)//得到临时对象的副本
{
//处理动作.
}