(C++) 错误:'invalid_argument'未在此范围内声明
(C++) error: 'invalid_argument' was not declared in this scope
我正在使用Eclipse C/C++和MinGW编译器。我已经在项目属性的c/c++Build下的Miscellaneous GCC c Compiler Settings中添加了-std=c++11标志。我知道这可能是一件简单的事情,但我无法解决这个错误。
Date.h
#include <iostream>
using namespace std;
class Date {
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
private:
int month;
int day;
int year;
static const int days[];
};
Date.cpp
#include <iostream>
#include <string>
#include "Date.h"
using namespace std;
const int Date::days[] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
Date::Date(int month, int day, int year){
setDate(month, day, year);
}
void Date::setDate(int month, int day, int year){
if (month >= 1 && month <= 12){
this->month = month;
} else {
// error
invalid_argument("month must be within the range [0, 12]");
}
...
}
编译器消息:
..Date.cpp: In member function 'void Date::setDate(int, int, int)':
..Date.cpp:25:60: error: 'invalid_argument' was not declared in this scope
invalid_argument("month must be within the range [0, 12]");
std::invalid_argument
在标头<stdexcept>
中定义。包括它。
您可能还意味着throw
对象,而不仅仅是构造它:
throw invalid_argument("month must be within the range [1, 12]");
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明