下面程序的最后几行:
“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 跳转至页
回复
打赏帖 | |
---|---|
分享一种检测按键状态的方法被打赏20分 | |
周末总结一下,STM32C0系列的开发经验被打赏50分 | |
【换取手持数字示波器】MicrochipMPLABHarmony框架下定时器配置被打赏20分 | |
【换取手持数字示波器】MicrochipMPLABHarmony框架下PWM配置被打赏20分 | |
【Cortex-M】Systick Timer使用被打赏10分 | |
分享汽车防盗系统的组成与分类(一)被打赏5分 | |
VOFA+波形显示+JYD-31蓝牙发送和解析不定长数据被打赏10分 | |
【换取手持数字示波器】-STM32F4PWM控制LED灯管亮度被打赏22分 | |
【换取手持数字示波器】STM32F4驱动RPR-0521RS照度、接近一体型传感器被打赏23分 | |
宏定义和const关键字定义被打赏5分 |