下面程序的最后几行:
“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 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| OK1126B-S开发板下函数构建及步进电机驱动控制被打赏¥25元 | |
| 【S32K3XX】LPI2C 参数配置说明被打赏¥20元 | |
| OK1126B-S开发板的脚本编程及应用设计被打赏¥27元 | |
| 5v升压8.4v两节锂电池充电芯片,针对同步和异步的IC测试被打赏¥35元 | |
| 【S32K3XX】S32DS LPI2C 配置失败问题解决被打赏¥22元 | |
| 【S32K3XX】FLASH 的 DID 保护机制被打赏¥19元 | |
| OK1126B-S开发板串口通信及其使用被打赏¥18元 | |
| 【S32K3XX】多核 CORE ID 获取被打赏¥18元 | |
| OK1126B-S开发板的GPIO资源及其使用被打赏¥20元 | |
| 【分享开发笔记,赚取电动螺丝刀】三分钟快速上手驱动屏幕(Arduino IDE环境)被打赏¥23元 | |
我要赚赏金
