将数组传递给函数
时出错 数组: int red_eachpix[MAX_PIX] = { 0 }
功能:
void sum_individualpix(int *pixels, int pixle) {
pixels[(pixle - 1)]++;
}
错误:错误C2664:'void sum_individualpix(int,int)':无法将参数1从'int [255]'转换为'int'
整个计划如下:
#define MAX_PIX 255
#define WIDTH 25
#define HEIGHT 25
void sum_individualpix(int , int); // I think the error is here
int main()
{
int X, Y, red, counter = 0;
int red_eachpix[MAX_PIX] = { 0 }, Red[WIDTH][HEIGHT] = { 0 };
long sum_red = 0;
in.open("basicval.txt");
if (in)
{
in >> X >> Y >> red; //Data is in form of: X Y B1(red pixel value)
while (!in.eof())
{
counter++;
sum_red += red;
Red[X][Y] = red;
sum_individualpix(red_eachpix, red); //Getting Error here
in >> X >> Y >> red;
}
double avg_red = (double)sum_red / counter;
cout << "Average Value for Red = " << avg_red << endl;
}
in.close();
getchar();
}
void sum_individualpix(int *pixels, int pixle) {
pixels[(pixle - 1)]++;
}
以防万一有人想知道程序读取图像的像素值,而图像本身已被程序转换为ASCII值
已编辑: 实际上是Red[WIDTH][HEIGHT]
&amp; int X, Y, red, counter = 0;
并非错误。我不小心写错了。
答案 0 :(得分:1)
您定义了两次相同名称'red':
int X, Y, red, counter = 0;
int red_eachpix[MAX_PIX] = { 0 }, red[WIDTH][HEIGHT] = { 0 };
答案 1 :(得分:1)
你有int X, Y, red, counter = 0;
,一个名为红色的int变量
还有red[WIDTH][HEIGHT] = { 0 };
int数组,名为red
答案 2 :(得分:0)
void sum_individualpix(int *pixels, int pixle) {
pixels[(pixle - 1)]++; //Shows that first argument type is array
}
错误是函数声明void sum_individualpix(int , int)
第一个(参数)数据类型说明符实际上是数组(int [])而不是整数(int)所以声明应该是已更改为void sum_individualpix(int[], int)