[英]Unused variable error, altought it shouldent
I`m having some errors in my c++ program. 我的C ++程序出现错误。 I need to create out of 2 sorted list, a 3-rd which is sorted out of the first 2. 我需要创建2个排序列表,第3个从前2个排序出来。
void arrayInp()
/* Create 2 vectors by the length defined by the user*/
{
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
int rez[20];
cout<<"enter length of the first array: ";
cin>>a;
cout<<"enter length of the second array: ";
cin>>b;
cout<<"insert first array:";
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
cout<<"insert second array:";
for (j=0;j<=a;j++)
cin>>d;
B.els[j]=d;
cout<<", ";
}
The header i imported is containing: 我导入的标头包含:
const int dim = 10;
struct Array
{
int n;
int els[dim];
};
Thank you for your help 谢谢您的帮助
The warning possibly comes from rez
, which you don't use. 该警告可能来自rez
,您不会使用它。
First time I looked at the code, I could tell you're coming from python. 第一次查看代码时,我可以断定您来自python。 The code results in undefined behavior (possibly, depending what indexes get to be): 该代码导致未定义的行为(可能取决于要成为的索引):
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
//...
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
See the error? 看到错误了吗?
for (i=0;i<=a;i++)
{
cin>>c;
}
A.els[i]=c;
cout<<", ";
How about now? 现在怎么样?
If you are a beginner, try and get Clang to compile your code. 如果您是初学者,请尝试让Clang编译您的代码。 It puts a particular emphasis on digestible error messages. 它特别强调可消化的错误消息。
If you cannot use it, you still have the online version , though it's limited in terms of dependencies obviously. 如果您不能使用它,那么您仍然可以使用在线版本 ,尽管它在依赖性方面显然受到限制。
/tmp/webcompile/_1981_1.cc:18:5: warning: unused variable 'rez' [-Wunused-variable]
int rez[20];
^
1 warning generated.
You can see, in general, for diagnosis: 通常,您可以看到用于诊断的信息:
And for this particular warning: the name of the unused variable is actually shown. 对于此特定警告:实际显示未使用的变量的名称。
Do yourself a favor, get a friendly compiler ;) 帮个忙,得到一个友好的编译器;)
rez
is the unused variable, not A
or B
. rez
是未使用的变量,不是A
或B
And you have several other errors. 而且您还有其他几个错误。 The braces for one thing. 大括号为一件事。 And you ask for more input parameters than the user is prepared to give (in (i=0;i<=a;i++)
). 并且您要求的输入参数超出了用户准备提供的输入参数(在(i=0;i<=a;i++)
)。 And you use a
for an upper boundary instead of b
in the second block. 然后在第二个块中使用a
代替上边界b
。 Copy and paste error? 复制和粘贴错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.