指向功能的指针 [英] Pointers to functions

查看:99
本文介绍了指向功能的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在哪些情况下指向函数的指针可能比直接函数调用更有效/方便?

在我到目前为止找到的示例中,我发现使用函数指针没有优势

。相反,代码更难以b $ b读取。


问候,

克里斯

解决方案



Christian Christmann写道:



在哪些情况下指向函数的指针可能更多<有效/方便比直接函数调用?

在我到目前为止找到的例子中,我看到使用函数指针没有优势。相反,代码更难阅读。




我建议你学习`qsort()`(或`bsearch()`)函数,尤其是

你可以将指针传递给你自己的比较函数。




Christian Christmann写道:



在哪些情况下指向函数的指针可能比直接函数调用更有效/方便?

在我迄今为止找到的示例中,我发现使用指向函数的指针没有任何优势。相反,代码更难阅读。




尝试编写适用于任意数据的排序算法

类型。 />




" Christian Christmann" < PL ***** @ yahoo.de>在留言中写道

news:pa **************************** @ yahoo.de ... < blockquote class =post_quotes>

在哪种情况下指向函数的指针可能比直接函数调用更有效/方便?

在示例中到目前为止,我发现使用指针函数没有优势。相反,代码更难以阅读。

问候,
Chris




我在人工中使用它们神经网络实施。人工神经网络

需要激活功能来将输入归一化到给定范围。它可以根据问题确定这个可定义的b $ b因此使用

指向函数的指针是适用的,考虑到这个

操作将会更快执行了很多次。


至于代码更难阅读,我认为这些声明最初让人感到困惑,但是一旦你知道如何就会很好。记得回到学习C,

我打赌普通指针也难以阅读;-)


Allan

Hi,

in which situations pointers to functions might be more
efficient/convenient than a direct function call?

In the example I''ve found so far, I see no advantage of
using pointers to functions. Rather the code is harder to
read.

Regards,
Chris

解决方案


Christian Christmann wrote:

Hi,

in which situations pointers to functions might be more
efficient/convenient than a direct function call?

In the example I''ve found so far, I see no advantage of
using pointers to functions. Rather the code is harder to
read.



I suggest you study the `qsort()` (or `bsearch()`) function, especially
the bit where you can pass a pointer to your own comparison function.



Christian Christmann wrote:

Hi,

in which situations pointers to functions might be more
efficient/convenient than a direct function call?

In the example I''ve found so far, I see no advantage of
using pointers to functions. Rather the code is harder to
read.



Try writing a sort algorithm that works on arbitrary data
types.



"Christian Christmann" <pl*****@yahoo.de> wrote in message
news:pa****************************@yahoo.de...

Hi,

in which situations pointers to functions might be more
efficient/convenient than a direct function call?

In the example I''ve found so far, I see no advantage of
using pointers to functions. Rather the code is harder to
read.

Regards,
Chris



I have used them in an Artificial Neural Network implementation. ANNs
require an activation function to normalise the inputs to a given range. It
is desirable to have this definable depending on the problem so using
pointers to functions is applicable and indeed faster considering this
operation will be executed many times.

As for the code being harder to read, I think the declarations are confusing
at first but they are fine once you know how. Remember back to learning C,
I bet normal pointers were difficult to read too ;-)

Allan


这篇关于指向功能的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆