Linux 未在此范围内为 g++ 4.1.2 声明 runtime_error

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5527091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:29:56  来源:igfitidea点击:

runtime_error was not declared in this scope for g++ 4.1.2

c++linuxgcc

提问by Dat Chu

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.

相同的代码在 gcc 4.5.2 上运行良好,但是当尝试在 gcc 4.1.2 上编译它时,出现错误‘runtime_error' was not declared in this scope

I do have

我有

#include <stdexcept>

Is this a problem with gcc 4.1.2?

这是 gcc 4.1.2 的问题吗?

Code excerpt

代码摘录

// Constructor
if (resource cannot be acquired)
  throw std::runtime_error("Blah Blah");

采纳答案by Puppy

Visual Studio says that runtime_errorshould be defined in <stdexcept>, so I'm guessing that GCC 4.1.2 is just out of date here.

Visual Studio 说runtime_error应该在 中定义<stdexcept>,所以我猜 GCC 4.1.2 在这里刚刚过时。

回答by ildjarn

Do you have using namespace std;or using std::runtime_error;? If not, then you need to fully qualify the name and use std::runtime_errorrather than just runtime_error.

你有using namespace std;using std::runtime_error;吗?如果没有,那么您需要完全限定名称并使用std::runtime_error而不仅仅是runtime_error.

回答by B?ови?

gcc 4.1 is relatively old. 4.5 is more standard compliant. Maybe you triggered a compiler's bug

gcc 4.1 相对较旧。4.5 更符合标准。也许你触发了编译器的错误