下面程序的最后几行:
“Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();”,能编译通过并运行成功,想知道为什么。。。如果没有传入参数Array_Fountion.name,Array_Fountion.length,显然会报错,混乱中。。。。。
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int *name;
int length;
void (*show)();
void (*insertion_sort)();
}array;
void show_array(int *A,int A_Length)
{
int i=0;
for(i=0;i<A_Length;i++)
{
printf("%d ",A[i]);
}
printf("\n");
}
void Insertion_Sort(int A[],int n)
{
int j=0,i=0;
int key=0;
for(j=1;j<n;j++)
{
key=A[j];
i=j-1;
while(i>=0&&key<A[i])
{
A[i+1]=A[i];
i--;
}
A[i+1]=key;
}
printf("Insertion_Sort Done!\n");
}
void Initial_Array(array *string,int *Array_Int,int Array_Length)
{
string->name=Array_Int;
string->length=Array_Length;//等价于(*string).length=11;
string->show=show_array;//等价于show=&show_array
string->insertion_sort=Insertion_Sort;
}
int main()
{
int A[]={8,7,6,5,4,3,2,123,45,666};
array Array_Fountion;
Initial_Array(&Array_Fountion,A,sizeof(A)/sizeof(*A));
Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();
return 0;
}
共7条
1/1 1 跳转至页
编译的错误信息如下:
--------------------配置: test02 - Debug--------------------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
..\test02.cpp:
Warning W8004 ..\test02.cpp 16: 'i' is assigned a value that is never used in function show_array(int *,int)
Warning W8004 ..\test02.cpp 27: 'key' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'i' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'j' is assigned a value that is never used in function Insertion_Sort(int *,int)
Error E2034 ..\test02.cpp 46: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2034 ..\test02.cpp 47: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2226 ..\test02.cpp 56: Extra parameter in call in function main()
*** 3 errors in Compile ***
test02.obj - 3 个错误, 4 个警告
--------------------配置: test02 - Debug--------------------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
..\test02.cpp:
Warning W8004 ..\test02.cpp 16: 'i' is assigned a value that is never used in function show_array(int *,int)
Warning W8004 ..\test02.cpp 27: 'key' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'i' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'j' is assigned a value that is never used in function Insertion_Sort(int *,int)
Error E2034 ..\test02.cpp 46: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2034 ..\test02.cpp 47: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2226 ..\test02.cpp 56: Extra parameter in call in function main()
*** 3 errors in Compile ***
test02.obj - 3 个错误, 4 个警告
共7条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |