std :: out_of_range的问题 [英] Problem with std::out_of_range
问题描述
我有以下代码:
#include< stdexcept>
int main(){
int i = 10;
int arr [i];
int index = 11;
if(index i ){
throw std :: out_of_range();
}
else {
arr [index] = 33;
}
返回0;
}
但是当我编译时,我得到:
没有匹配函数来调用?std :: out_of_range :: out_of_range()?
/ usr / lib / gcc / i486-linux-gnu / 4.1.2 /../../../../ include / c ++ / 4.1.2 / stdexcept:99:
注意:候选人是:std :: out_of_range :: out_of_range(const std :: string&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../ .. /include/c++/4.1.2/stdexcept:97:
note:std :: out_of_range :: out_of_range(const
std :: out_of_range&)
为什么我不能以这种方式使用std :: out_of_range()?
*桌面:
我有以下代码:
#include< stdexcept>
int main(){
int i = 10;
int arr [i];
非标准C ++。
int index = 11;
if(index i){
throw std :: out_of_range();
}
else {
arr [index] = 33;
}
返回0;
没必要:main很特别,请查看
main的各种特殊规则。
}
但是当我编译时我得到:
没有匹配函数来调用?std :: out_of_range :: out_of_range()?
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/ 4.1.2 / stdexcept:99:
注意:候选人是:std :: out_of_range :: out_of_range(const std :: string&)
/ usr / lib / gcc /i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:97:
注意:std :: out_of_range: :out_of_range(const
std :: out_of_range&)
为什么我不能以这种方式使用std :: out_of_range()?
错误消息告诉你(1)没有默认构造函数,你试图使用的那个
,(2)但是那里是一个构造函数,它采用std :: string
参数,(3)有一个复制构造函数。
为什么你不只是/读/错误消息?
-
答:因为它弄乱了人们通常阅读文本的顺序。
问:为什么会这样这么糟糕吗?
A:热门帖子。
问:usenet和电子邮件中最烦人的是什么?
5月21日下午6:44,桌面< f ... @ sss.comwrote:
我有以下代码:
#include< stdexcept>
int main(){
int i = 10;
int arr [i];
int index = 11;
if(index i){
throw std :: out_of_range();
}
else {
arr [index] = 33;
}
返回0; < br $>
}
但是当我编译时我会得到:
没有匹配函数来调用' 'std :: out_of_range :: out_of_range()''
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include /c++/4.1.2/stdexcept:99:
注意:候选人是:std :: out_of_range :: out_of_range(const std :: string&)
/ usr / lib / gcc / i486-linux-gnu / 4.1.2 /../../../../ include / c ++ / 4.1.2 / stdexcept:97:
note:std: :out_of_range :: out_of_range(const
std :: out_of_range&)
为什么我不能以这种方式使用std :: out_of_range()?
静态方法std :: out_of_range不存在没有参数,
但是带有std :: string来表示消息显示何时抛出
异常。
例如:在抛出
''std :: out_of_range''的实例后终止调用
what():我的消息
desktop写道:
我有以下代码:
#include< stdexcept>
int main(){
int i = 10;
int arr [i];
int index = 11;
if(index i){
throw std :: out_of_range();
}
else {
arr [index] = 33;
}
返回0;
}
为什么我不能以这种方式使用std :: out_of_range()?
因为有
没有匹配函数来调用?? std :: out_of_range :: out_of_range()的ΔΣ
你应该
注意:候选人是:std :: out_of_range :: out_of_range(const std: :string&)
I have the following code:
#include <stdexcept>
int main(){
int i = 10;
int arr[i];
int index = 11;
if (index i) {
throw std::out_of_range();
}
else {
arr[index] = 33;
}
return 0;
}
but when I compile I get:
no matching function for call to ?std::out_of_range::out_of_range()?
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:99:
note: candidates are: std::out_of_range::out_of_range(const std::string&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:97:
note: std::out_of_range::out_of_range(const
std::out_of_range&)
why can''t I use std::out_of_range() in this manner?
* desktop:I have the following code:
#include <stdexcept>
int main(){
int i = 10;
int arr[i];Not standard C++.
int index = 11;
if (index i) {
throw std::out_of_range();
}
else {
arr[index] = 33;
}
return 0;Not necessary: main is special, check out the various special rules for
main.
}
but when I compile I get:
no matching function for call to ?std::out_of_range::out_of_range()?
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:99:
note: candidates are: std::out_of_range::out_of_range(const std::string&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:97:
note: std::out_of_range::out_of_range(const
std::out_of_range&)
why can''t I use std::out_of_range() in this manner?The error messages tell you (1) there is no default constructor, the one
you attempted to use, (2) but there is a constructor taking std::string
argument, and (3) there is a copy constructor.
Why don''t you just /read/ the error messages?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On May 21, 6:44 pm, desktop <f...@sss.comwrote:I have the following code:
#include <stdexcept>
int main(){
int i = 10;
int arr[i];
int index = 11;
if (index i) {
throw std::out_of_range();
}
else {
arr[index] = 33;
}
return 0;
}
but when I compile I get:
no matching function for call to ''std::out_of_range::out_of_range()''
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:99:
note: candidates are: std::out_of_range::out_of_range(const std::string&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stdexcept:97:
note: std::out_of_range::out_of_range(const
std::out_of_range&)
why can''t I use std::out_of_range() in this manner?The static method std::out_of_range doesn''t exist without arguments,
but with a std::string to indicate a message to display when the
exception is thrown.
e.g. : terminate called after throwing an instance of
''std::out_of_range''
what(): My message
desktop wrote:
I have the following code:
#include <stdexcept>
int main(){
int i = 10;
int arr[i];
int index = 11;
if (index i) {
throw std::out_of_range();
}
else {
arr[index] = 33;
}
return 0;
}
why can''t I use std::out_of_range() in this manner?Because there is
no matching function for call to a??std::out_of_range::out_of_range()a??You should
note: candidates are: std::out_of_range::out_of_range(const std::string&)
这篇关于std :: out_of_range的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!