无法将参数“1”的“char*”转换为“int*”到“int median(int*, int)” array2 = m

cannot convert ‘char*’ to ‘int*’ for argument ‘1’ to ‘int median(int*, int)’ array2 = median(array,size);

本文关键字:int median array2 转换 参数 char      更新时间:2023-10-16

我的问题是我在标题中指定的: test_median.cpp:

在函数 'int main()' 中: test_median.cpp:26:27: 错误: 无法转换 "char*"到"int*"表示参数"1"到"int median(int*, int)"

array2 = median(array,size);

所以这是我的代码。这是测试器代码;

#include <iostream>
#include <cmath>
#include "IpFunctions.h"
using namespace std;
int main()
{
int size;
cout<< "size gir" <<endl;
cin >> size;
int i;
char array[size];
cout<< "değerleri gir"<<endl;
for (i=0;i<size;i=i+1)
{
cin >> array[i];
}
char array2[size];
array2 = median(array,size);
cout<<"array2 = "<<array2<<endl;
return 0;
}

这是中值函数代码:

#include <iostream>
#include <cmath>
using namespace std;
int median(char array[], int size)
{
int i = 0;
int m,n;
while (i<size)
{
    if (array[i]>array[i+1])
    {
    m = array[i]; n = array[i+1];
    array[i] = n; array[i+1] = m;
    i=i+1;
    }
    else
    {
    i=i+1;
    }
}
return *array;
}

最后是"IpFunctions.h"标头:

// this is just a headerfile that you add your Image processing functions' prototypes.
// when testing your functions with a main function
// main needs a prototype of the function
//Image medianfiltering(Image &inimg, const int size );
int median(int array[],int size);
// when you type a function add the header here !!! 
// such as 
// Image negative(Image &inimg);

所以我只想创建一个函数来获取数组的中位数并返回该数组。

标题中

int median(int array[],int size);

在.cpp文件中

int median(char array[], int size)

您的主要内容正在尝试调用第一个(这是它唯一知道的)