누구든지이 코드에서 오류를 해결할 수 있습니까?오버로드 된 기능에서 오류가 발생했습니다.
# include<iostream>
using namespace std;
void bubble_sort (int a[], int size);
float bubble_sort (float b[], int size);
int read (int a[], int size);
float read (float b[], int size);
void display (int a[], int size);
void display (float b[], int size);
int main()
{
int const size=10;
int a[10];
int b[10];
read (a,size);
read (b,size);
bubble_sort(a,size);
bubble_sort(b,size);
display(a, size);
display(b, size);
return 0;
}
int read (int a[], int size)
{
cout<<"Enter the integer values:";
for (int i=0; i<10;i++)
cin>>a[i];
}
float read (float b[], int size)
{
cout<<"Enter the float values :";
for (int i=0; i<10;i++)
cin>>b[i];
}
void bubble_sort (int a[], int size)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size - 1; j++)
if (a[j]>a[j + 1])
{
swap = a[j];
a[j] = a[j + 1];
a[j + 1] = swap;
}
}
}
float bubble_sort (float b[], int size)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size - 1; j++)
if (b[j]>b[j + 1])
{
swap = b[j];
b[j] = b[j + 1];
b[j + 1] = swap;
}
}
}
void display (int a[], int size)
{
for (int i=0;i<size;i++)
cout<<a[i]<<" ";
}
void display (float b[], int size)
{
cout<<endl;
for(int i=0 ;i<size; i++)
cout<<b[i]<<" ";
}
컴파일러는 컨텍스트 유형 정보없이 오버로드 된 기능을 보여줍니다. 하지만 오버로드 된 함수를 사용해야합니다. 내가 어떻게 해결할 수 있니? bubble_sort
에서
In function ‘void bubble_sort(int*, int)’:
error: overloaded function with no contextual type information
swap = a[j];
^
error: cannot resolve overloaded function ‘swap’ based on conversion to type ‘int’
a[j + 1] = swap;
대신 함수 템플릿을 시도하십시오 – taocp
_ '컴파일러는 컨텍스트 유형 정보없이 오버로드 된 함수를 보여줍니다'어떻게? 오류 텍스트? –
당신은'swap'을 사용하고 있으며 그것을 선언하지 않았습니다. 'std :: swap' 함수 템플릿이있을 수 있습니다. – chris