C ++函数指针 [英] C++ Function Pointers

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

问题描述

如何初始化

C ++中任何特定函数的函数指针?


这样就可以清楚地指定

由该类的不同对象调用...

ie

而不是


a.function ();



b.function();


使用此 - >

int(* funcptr)(void); ????怎么样?

How to initialise a function pointer for any particular function in
C++ ?

so that it would clearly specify difference between the functions that
are called by different objects of that class ...
i.e
instead of

a.function();
or
b.function();

use of this -->
int (*funcptr)(void); ???? How ?

推荐答案



" chetan" < RO **** @ indiatimes.com>在消息中写道

news:4c ************************** @ posting.google.c om ...

"chetan" <ro****@indiatimes.com> wrote in message
news:4c**************************@posting.google.c om...
如何为C ++中的任何特定函数初始化函数指针?

以便明确指定调用函数之间的区别由该类的不同对象...
而不是

a.function();

b.function();

使用这个 - >
int(* funcptr)(void); ????怎么样?
How to initialise a function pointer for any particular function in
C++ ?

so that it would clearly specify difference between the functions that
are called by different objects of that class ...
i.e
instead of

a.function();
or
b.function();

use of this -->
int (*funcptr)(void); ???? How ?




你在问什么?函数指针''如何指定由该类的不同对象调用的函数之间的差异



这是什么意思?


我想你将不得不再次提问并且这次更加谨慎地选择你的话语

。我相信你知道你的意思但我不认为

对其他人来说非常清楚。有时它会发布一些伪代码

来更清楚地表达您想要做的事情。


john



What are you asking? How can a function pointer ''specify the difference
between the functions that are called by different objects of that class''?
What does that mean?

I think you''re going to have to ask again and choose your words a little
more carefully this time. I''m sure you know what you mean but I don''t think
its very clear to anyone else. Sometimes it helps to post some pseudo code
to more clearly express what you want to do.

john

ro****@indiatimes.com (chetan)在留言中写道:< 4c **** **********************@posting.google。 com> ...
ro****@indiatimes.com (chetan) wrote in message news:<4c**************************@posting.google. com>...
如何为C ++中的任何特定函数初始化函数指针?

以便明确指定
由该类的不同对象调用...


a.function();

b。 function();

使用这个 - >
int(* funcptr)(void); ????怎么样?
How to initialise a function pointer for any particular function in
C++ ?

so that it would clearly specify difference between the functions that
are called by different objects of that class ...
i.e
instead of

a.function();
or
b.function();

use of this -->
int (*funcptr)(void); ???? How ?




int(* funcptr)();不要使用虚空。


我不清楚你要求的是什么,但我的猜测是你

想打电话给上课成员函数由函数指针,就像你可以为普通函数做
。有一个指向会员的功能,你可以使用
。类似于:int(C :: * mem_func_ptr)()其中C是类。


-Arijit



int (*funcptr)(); Don''t use void.

I don''t clearly understand what you are asking for, but my guess is you
want to call a class member function by a function pointer, like you can
do for ordinary functions. There is a pointer-to-member-function that you
can use. Something like: int (C::*mem_func_ptr)() where C is the class.

-Arijit


chetan写道:
chetan wrote:
如何为C ++中的任何特定函数初始化函数指针?
您可以将指定函数的名称指定给指针:

function_pointer = Function_Name;


另请注意,您只能指定匹配的函数函数指针的

签名。


这样就可以清楚地指定
由该类的不同对象调用的函数之间的差异...


a.function();

b.function();
使用这个 - >
int(* funcptr)(void); ????怎么样?
How to initialise a function pointer for any particular function in
C++ ? You assign the name of the function to the pointer:
function_pointer = Function_Name;

Also be aware that you can only assign functions that match the
signature of the function pointer.

so that it would clearly specify difference between the functions that
are called by different objects of that class ...
i.e
instead of

a.function();
or
b.function();

use of this -->
int (*funcptr)(void); ???? How ?



看起来你想要一个指向成员函数的指针。

阅读常见问题解答以获得一个很好的解释:
http://www.parashift.com/c++-faq-lit ... o-members.html

-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome .txt

C ++常见问题: http ://www.parashift.com/c++-faq-lite

C常见问题: http://www.eskimo.com/~scs/c-faq/top.html

alt。 comp.lang.learn.c-c ++ faq:
http:// www.comeaucomputing.com/learn/faq/

Oth呃网站:
http://www.josuttis.com - C ++ STL图书馆书


Looks like you want a pointer to a member function.
Read the FAQ for a good explanation:
http://www.parashift.com/c++-faq-lit...o-members.html
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book


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

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