问题描述
你好,
这段代码给了我在弹出之前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;
}
因为C ++中没有要求这样做。
john
因为C ++中没有要求这样做。
john
谢谢John,
意味着它是专有的MS解决方案,
和其他c ++编译器供应商并不一定要遵循?
kruno
因为没有要求在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;
}
Because there is no requirement in C++ do to so.
john
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
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中弹出空栈 - 不会抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!