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

Dat*_*Chu 9 c++ linux gcc

相同的代码在gcc 4.5.2上工作正常但是当尝试在gcc 4.1.2上编译时,我得到了错误‘runtime_error’ was not declared in this scope.

我有

#include <stdexcept>
Run Code Online (Sandbox Code Playgroud)

这是gcc 4.1.2的问题吗?

代码摘录

// Constructor
if (resource cannot be acquired)
  throw std::runtime_error("Blah Blah");
Run Code Online (Sandbox Code Playgroud)

Pup*_*ppy 6

Visual Studio说runtime_error应该定义<stdexcept>,所以我猜测GCC 4.1.2在这里已经过时了.


ild*_*arn 5

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