catch而不尝试编译成功 [英] catch without try compiling successfully
本文介绍了catch而不尝试编译成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码使用g ++版本5.1.0成功编译。注意在成员函数中没有相应的
try
的 catch / code>。我想知道这种语法是否合法,如果是这样,它有什么效果?
struct foo
{
void bar()
{
}
catch(...)
{
}
};
int main()
{
foo f;
f.bar();
return 0;
}
最初在 解决方案
p>您提供的示例,
struct foo
{
void bar()
{
}
catch(...)
{
}
};
…是无效的标准C ++。
它可能是一个g ++语言扩展。
catch
在您链接的问题看起来像函数catch块,除了这也需要一个 try
关键字。
The following code compiles successfully with g++ version 5.1.0. Notice the catch
without a corresponding try
in the member function foo::bar()
. I was wondering if this syntax was legal and if so what effect it had?
struct foo
{
void bar()
{
}
catch (...)
{
}
};
int main ()
{
foo f;
f.bar();
return 0;
}
Originally seen in Catch block in constructor without try
解决方案
The example you give,
struct foo
{
void bar()
{
}
catch (...)
{
}
};
… is not valid standard C++.
It might be a g++ language extension.
The catch
es in the question you linked to look like function catch blocks, except that also that requires a try
keyword.
这篇关于catch而不尝试编译成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文