未在此范围内为 g++ 声明 runtime_error 4.1.2
相同的代码在 gcc 4.5.2 上运行良好,但是当尝试在 gcc 4.1.2 上编译它时,我收到错误 'runtime_error' was not returned in this scope
。
我确实有
#include <stdexcept>
这是 gcc 4.1.2 的问题吗?
代码摘录
// Constructor
if (resource cannot be acquired)
throw std::runtime_error("Blah Blah");
The same code is working fine on gcc 4.5.2 but when trying to compile it on gcc 4.1.2, I get the error ‘runtime_error’ was not declared in this scope
.
I do have
#include <stdexcept>
Is this a problem with gcc 4.1.2?
Code excerpt
// Constructor
if (resource cannot be acquired)
throw std::runtime_error("Blah Blah");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Visual Studio 说
runtime_error
应该在
中定义,所以我猜测 GCC 4.1.2 在这里已经过时了。Visual Studio says that
runtime_error
should be defined in<stdexcept>
, so I'm guessing that GCC 4.1.2 is just out of date here.您有
using namespace std;
或using std::runtime_error;
吗?如果没有,那么您需要完全限定名称并使用std::runtime_error
而不仅仅是runtime_error
。Do you have
using namespace std;
orusing std::runtime_error;
? If not, then you need to fully qualify the name and usestd::runtime_error
rather than justruntime_error
.gcc 4.1 相对较旧。 4.5 更符合标准。也许你触发了编译器的错误
gcc 4.1 is relatively old. 4.5 is more standard compliant. Maybe you triggered a compiler's bug