错误:名称查找“我”改变ISO'为'作用域 [英] error: name lookup of 'i' changed for ISO 'for' scoping
问题描述
我已经看过类似这样仍然无法找出什么是错我的code等话题。以下是在我的计划找到阵列的平均值(平均)的功能。我得到错误的标题:错误:的我改变ISO'名称查找为作用域与注意事项如下:如果你使用。-fpermissize'G ++会接受你的code
双GetMean(双数组[],INT ArrayLength)
{
INT求和,平均值;
的for(int i = 0; I< ArrayLength;我++)
{
总和= SUM +阵列[我]
} 平均= SUM /阵列[我] 回归均值;
}
意见和解释是可爱的,所以我能理解我在做什么是地狱的错误:/
的for(int i = 0; I< ArrayLength;我++)
当你定义 I
在这样的为
头,其范围是为
循环。你不能使用它为
循环外像平均值= SUM /阵列[我];
在code。
将其更改为:
INT I;
对于(i = 0; I< ArrayLength;我++)
另外请注意你从来没有初始化总和
。
I have looked at other topics similar to this and still cannot find out what is wrong with my code. The following is a function in my program to find the Mean (Average) of Arrays. I get the error in the title: error: name lookup of 'i" changed for ISO 'for' scoping. following with note: if you use '-fpermissize' g++ will accept your code.
double GetMean ( double Array[], int ArrayLength )
{
int Sum, Mean;
for ( int i = 0; i < ArrayLength; i++ )
{
Sum = Sum + Array[i];
}
Mean = Sum / Array[i];
return Mean;
}
Ideas and explanation would be lovely so I can understand what the hell I'm doing wrong :/
for (int i = 0; i < ArrayLength; i++)
When you define i
in the for
header like this, its scope is inside the for
loop. You can't use it outside the for
loop like Mean = Sum / Array[i];
in your code.
Change it to:
int i;
for (i = 0; i < ArrayLength; i++)
Also note you never initialize Sum
.
这篇关于错误:名称查找“我”改变ISO'为'作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!