user-0 提问: 关于一个函数指针数组（error: array type has incomplete element type）

回复:
user: user-0
content: 引用 3 楼 JieWinli 的回复: typedef double (*FUN)(double);  void transform(double , double , int, FUN func); double twice(double); double half(double);  int main(void)  {     int i,j;      double source[NUM] = {0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0}; 20     	double target[NUM];     FUN abc[VAR] = {sqrt, sin, twice, half};       for(i = 0; i < VAR; i++) 	{          for(j = 0; j < NUM; j++)         {              transform(source[j], target[j],  NUM, abc[i]);         }      }     return 0;  }  void transform(double source, double target, int n, FUN func)  {     for(int i = 0; i < n; i++)         target = func(source); } double twice(double x) {     return 2.0 * x; } double half(double x) {     return x/2.0; }  谢谢，你指出的跟楼上两位一样都很准确，就是typedef那里的问题了！

user: user-0
content: 引用 2 楼 KenZhang1031 的回复:typedef double (*FUN)(double);  for(int i = 0; i < VAR; i++) 	{ 		if(funcs[i] != NULL) 		{ 			for(int j = 0; j < NUM; j++) 			{ 				transform(source[j], target[j], NUM, funcs[i]); 			} 		} 	} 谢谢，你指出的问题很准确，果然就是typedef那里的问题！

user: user-0
content: 引用 1 楼 user-3 的回复:不知道是不是这个效果 /* ex11, ch 14 */  #include <stdio.h> #include <math.h>   #define NUM		10 #define VAR		 4  typedef double (*FUN)(double);   void transform(double* , double* , int, double (*)(double)); double twice(double); double half(double);  int main(void) { 	double source[NUM] = {0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0}; 	double target[NUM]; 	FUN funcs[VAR] = {sqrt, sin, twice, half};          int i; 	for( i = 0; i < VAR; i++)        	    transform(source, target, NUM, funcs[i]);     return 0; }  void transform(double* source, double* target, int n, double (*func)(double)) {     int i;     for( i = 0; i < n; i++)         target[i] = func(source[i]); }  double twice(double x) {     return 2.0 * x; } double half(double x) {     return x/2.0; }  是的，应该就是typedef那里出了问题，应该先定义指针类型为函数指针而非直接定义成函数指针数组。谢谢！

user: user-1
content: 不知道是不是你想要的结果

user: user-1
content: typedef double (*FUN)(double);  void transform(double , double , int, FUN func); double twice(double); double half(double);  int main(void)  {     int i,j;      double source[NUM] = {0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0}; 20     	double target[NUM];     FUN abc[VAR] = {sqrt, sin, twice, half};       for(i = 0; i < VAR; i++) 	{          for(j = 0; j < NUM; j++)         {              transform(source[j], target[j],  NUM, abc[i]);         }      }     return 0;  }  void transform(double source, double target, int n, FUN func)  {     for(int i = 0; i < n; i++)         target = func(source); } double twice(double x) {     return 2.0 * x; } double half(double x) {     return x/2.0; }

user: user-2
content: typedef double (*FUN)(double);  for(int i = 0; i < VAR; i++) 	{ 		if(funcs[i] != NULL) 		{ 			for(int j = 0; j < NUM; j++) 			{ 				transform(source[j], target[j], NUM, funcs[i]); 			} 		} 	}

user: user-3
content: 不知道是不是这个效果 /* ex11, ch 14 */  #include <stdio.h> #include <math.h>   #define NUM		10 #define VAR		 4  typedef double (*FUN)(double);   void transform(double* , double* , int, double (*)(double)); double twice(double); double half(double);  int main(void) { 	double source[NUM] = {0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0}; 	double target[NUM]; 	FUN funcs[VAR] = {sqrt, sin, twice, half};          int i; 	for( i = 0; i < VAR; i++)        	    transform(source, target, NUM, funcs[i]);     return 0; }  void transform(double* source, double* target, int n, double (*func)(double)) {     int i;     for( i = 0; i < n; i++)         target[i] = func(source[i]); }  double twice(double x) {     return 2.0 * x; } double half(double x) {     return x/2.0; }