在visual c ++ express中弹出空栈 - 不会抛出异常? [英] poping empty stack in visual c++ express - doesn't throw exception ?

查看:249
本文介绍了在visual c ++ express中弹出空栈 - 不会抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


这段代码给了我在弹出之前deque empty错误

在调试配置模式下使用visual c ++ express。

为什么弹出空堆栈不会抛出异常?


取消注释该行解决问题。


Kruno

#include< iostream>

#include< stack>

使用命名空间std;


int main()

{

stack< ints;


试试

{

// if(s.empty())throw" something" ;;

s.pop();

}

catch(...)

{

cout< < hello empty stack <<结束;

}


返回0;

}

解决方案

KR ********** @ YAHOO.COM 写道:


你好,


这段代码给我在pop之前deque empty错误

在调试配置模式下使用visual c ++ express。

为什么弹出空堆栈不会抛出异常?



因为C ++中没有要求这样做。


john




John Harrison je napisao / la:

KR ** ********@YAHOO.COM 写道:


您好,


此代码给我流行之前deque empty错误

在调试配置模式下使用visual c ++ express。

为什么弹出空堆栈不会抛出异常?



因为C ++中没有要求这样做。


john



谢谢John,


意味着它是专有的MS解决方案,

和其他c ++编译器供应商并不一定要遵循?


kruno


KR ********** @ YAHOO.COM 写道:


John Harrison je napisao / la :


>> KR ********** @ YAHOO.COM写道:


>>>您好,

这段代码告诉我在弹出前deque empty错误
在调试配置模式下使用visual c ++ express。

为什么弹出空栈不会引发异常?


因为没有要求在C ++中这样做。

john




谢谢John,


意味着它是专有的MS解决方案,

和其他c ++编译器供应商没有必要遵循它?


kruno



这是正确的,弹出一个空堆栈是未定义的行为和

不同的供应商可以做任何他们认为最好的事情。


john


Hello,

This code give me "deque empty before pop" error
with visual c++ express in debug configuration mode.

Why poping empty stack doesn''t throw exception ?

Uncommenting the line solves the problem.

Kruno
#include<iostream>
#include<stack>
using namespace std;

int main()
{
stack<ints ;

try
{
//if (s.empty()) throw "something";
s.pop();
}
catch(...)
{
cout<< "hello empty stack" << endl;
}

return 0;
}

解决方案

KR**********@YAHOO.COM wrote:

Hello,

This code give me "deque empty before pop" error
with visual c++ express in debug configuration mode.

Why poping empty stack doesn''t throw exception ?

Because there is no requirement in C++ do to so.

john



John Harrison je napisao/la:

KR**********@YAHOO.COM wrote:

Hello,

This code give me "deque empty before pop" error
with visual c++ express in debug configuration mode.

Why poping empty stack doesn''t throw exception ?


Because there is no requirement in C++ do to so.

john

Thank you John,

means it is proprietary MS solution,
and other c++ compiler vendors doesn''t have to follow that?

kruno


KR**********@YAHOO.COM wrote:

John Harrison je napisao/la:

>>KR**********@YAHOO.COM wrote:

>>>Hello,

This code give me "deque empty before pop" error
with visual c++ express in debug configuration mode.

Why poping empty stack doesn''t throw exception ?


Because there is no requirement in C++ do to so.

john



Thank you John,

means it is proprietary MS solution,
and other c++ compiler vendors doesn''t have to follow that?

kruno

That''s right, popping an empty stack is undefined behaviour and
different vendors can do whatever they think is best.

john


这篇关于在visual c ++ express中弹出空栈 - 不会抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆