Ian Collins说: Ian Collins said: merrittr写道: merrittr wrote: >嗨我有一些分配函数指针的问题。 这很好用: int(* compar)()=增加; qsort(arr,MAX,sizeof(arr [0]),比较); 这不是: if(argv [1] =="减少") int(* compar)()=减少; if(argv [1] ==" increase") int(* compar)()=增加; qsort(arr,MAX,sizeof(arr [0]),compar); >Hi I am having some problems assigning function pointers.this works fine: int (*compar) () = increasing; qsort(arr, MAX, sizeof(arr[0]), compar);this doesn''t:if (argv[1] == "decreasing") int (*compar) () = decreasing;if (argv[1] == "increasing") int (*compar) () = increasing;qsort(arr, MAX, sizeof(arr[0]), compar); 你不能两次声明比较 You can''t declare compar twice 是的,他可以,但它不会做任何好事。 ,试试 Yes, he can, but it won''t do him any good. , try > int(* compar)(); >int (*compar)(); 使用 int(* compar)(const void *,const void *)不会更好吗? ? Wouldn''t he be better off withint (*compar)(const void *, const void *); ? > if(argv [1] =="减少") compar =减少; if(argv [1] ==" increase") compar = increase; >if (argv[1] == "decreasing") compar = decreasing;if (argv[1] == "increasing") compar = increasing; 查找strcmp他不是更好吗? - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 http://www.cpax.org.uk 电子邮件:rjh在上述域名中, - www。 Wouldn''t he be better off looking up strcmp? --Richard Heathfield"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.ukemail: rjh at the above domain, - www. Richard Heathfield写道: Richard Heathfield wrote: Ian Collins说: Ian Collins said: > merrittr写道: >merrittr wrote: > ;>嗨我在分配函数指针时遇到了一些问题。 这很好用: int(* compar)()=增加; qsort(arr,MAX,sizeof (arr [0]),比较); 这不是: if(argv [1] =="减少") int(* compar) ()=减少; if(argv [1] ==" increase") int(* compar)()=增加; qsort(arr,MAX,sizeof(arr [ 0]),比较); >>Hi I am having some problems assigning function pointers.this works fine: int (*compar) () = increasing; qsort(arr, MAX, sizeof(arr[0]), compar);this doesn''t:if (argv[1] == "decreasing") int (*compar) () = decreasing;if (argv[1] == "increasing") int (*compar) () = increasing;qsort(arr, MAX, sizeof(arr[0]), compar); 你不能两次声明比较 You can''t declare compar twice 是的,他可以,但它他不会对他好。 Yes, he can, but it won''t do him any good. 不是他在相同范围内的方式。 Not the way he did in the same scope. ,尝试 , try > int(* compar )(); >int (*compar)(); 使用 int(* compar)(const void *,const void *)不会更好吗? ? Wouldn''t he be better off withint (*compar)(const void *, const void *); ? 他会。 He would. > if(argv [ 1] ==减少)比较=减少; 如果(argv [1] ==增加)比较=增加; >if (argv[1] == "decreasing") compar = decreasing;if (argv[1] == "increasing") compar = increasing; 查找strcmp他不是更好吗? Wouldn''t he be better off looking up strcmp? 看一下写的时候会发生什么C ++整天? - Ian Collins。 See what happens when one writes C++ all day? --Ian Collins. 这篇关于试图分配函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 12:44